Mod rewrite 具有重写规则的服务器错误

Mod rewrite 具有重写规则的服务器错误,mod-rewrite,url-rewriting,Mod Rewrite,Url Rewriting,我已经更改了我的CMS,需要重定向一些旧的URL 我想做的是: 删除“博客/档案” 用破折号替换下划线 将“.html”替换为尾随斜杠 旧链接: http://example.com/blog/archives/the_post_title.html 新链接 http://example.com/the-post-title/ 我已经写过了,它在某一点上是有效的,但现在我得到了500个错误 RewriteRule ^([^_]*)_([^_]*_.*) $1-$2 [N] #Replac

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

我想做的是:

  • 删除“博客/档案”
  • 用破折号替换下划线
  • 将“.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)
    

    知道我为什么会出现服务器错误吗?

    您可以尝试用以下内容替换:

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

    谢谢你,乔恩。这确实解决了500错误,但现在我得到了404。如果我手动更改URL,我确实会收到新帖子,所以这不是问题所在。至于第一个请求,这些旧帖子来自一个生成HTML文件的旧CMS,因此我在/blog/archives目录下的.htaccess文件中有这些规则-因此当将URL返回到根目录(/$1/)时,它会处理这个问题。你会重定向到哪个URL?URL根本不会改变。这就是我的整个.htaccess<代码>在重写规则^(.*)上重写引擎(.*)$/$1-$2 RewriteCond%{REQUEST\u URI}!\u重写规则^(.*).html$/$1/[L,R=301]这是您文档根目录中的htaccess吗?