重写规则的服务器错误

时间:2012-06-15 04:47:59

标签: mod-rewrite url-rewriting

我已更改了CMS,需要重定向一些旧网址。

我想做的是:

  1. 删除“博客/档案”
  2. 用破折号替换下划线
  3. 用尾部斜线替换“.html”
  4. 旧链接:

    http://example.com/blog/archives/the_post_title.html
    

    新链接

    http://example.com/the-post-title/
    

    我已经写过,而且它一直在工作,但我现在得到500个错误。

    RewriteRule ^([^_]*)_([^_]*_.*) $1-$2 [N]   #Replace "_" with "-" loop until one left
    RewriteRule ^([^_]*)_([^_]*)$ /$1-$2        #Replace the last underscore
    RewriteRule ^(.*?).html$ /$1/ [L,R=301]     #Strip the ".html" and use the filename as the url, note this as "permanently moved" (301)
    

    知道我为什么会收到服务器错误吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试将其替换为:

RewriteRule ^(.*)_(.*)$ /$1-$2
RewriteCond %{REQUEST_URI} !_
RewriteRule ^blog/archive/(.*).html$ /$1/ [L,R=301]
相关问题