0

我更改了我的 CMS,需要重定向一些旧 URL。

我想做的是:

  1. 删除“博客/档案”
  2. 用破折号替换下划线
  3. 用斜杠替换“.html”

旧链接:

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)

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

4

1 回答 1

0

您可以尝试将其替换为:

RewriteRule ^(.*)_(.*)$ /$1-$2
RewriteCond %{REQUEST_URI} !_
RewriteRule ^blog/archive/(.*).html$ /$1/ [L,R=301]
于 2012-06-15T06:45:54.527 回答