我如何 301 重定向,例如:使用 .htaccess 的/Blog/
子目录/blog/
?
问问题
6932 次
3 回答
9
Redirect 301 /Blog /blog
于 2010-10-27T20:39:58.300 回答
3
马上想到的方式:
RewriteEngine on
RewriteBase /path/to/your/web/app
RewriteRule ^Blog$ blog [R=301,L]
RewriteRule ^Blog/(.*)$ blog/$1 [R=301,L]
可能有比 mod_rewrite 更好的方法,而且我不能 100% 确定外部重定向是否会正常工作——你可能需要完整的 URL——但是你去吧。
于 2010-10-27T20:39:21.717 回答
2
这是最简单的 .htaccess 解决方案,将其放在 /.htaccess 中:
Redirect 301 /Blog /blog
但这确实是有限的。如果您想捕获所有可能的 CaSe 拼写错误,并转发任何其他路径信息(例如 /Blog/foo/bar.html),请改用以下命令:
RedirectMatch 301 ^/[Bb][Ll][Oo][Gg](?<!blog)(/.*)?$ /blog$1
如需更多选项,可以使用完整的 .htaccess 生成器。
或者您可以使用基于 ModRewrite 的规则来获得最大的灵活性,但这可能是矫枉过正。
于 2010-10-27T21:02:27.633 回答