301 redirect .htaccess

你。 提交于 2019-11-26 17:16:00

问题


How do I 301 redirect, for example: a subdirectory /Blog/ to /blog/ with .htaccess?


回答1:


Redirect 301 /Blog /blog

Or use something like http://www.htaccessredirect.net/index.php




回答2:


The way that immediately comes to mind:

RewriteEngine on
RewriteBase /path/to/your/web/app
RewriteRule ^Blog$ blog [R=301,L]
RewriteRule ^Blog/(.*)$ blog/$1 [R=301,L]

There are probably much better ways than mod_rewrite, and I'm not 100% sure that the external redirects will work as they should -- you may need the full URL -- but there you go.




回答3:


This is the simplest .htaccess solution, place it in /.htaccess:

Redirect 301 /Blog /blog

But it's really limited. If you want to catch every possible CaSe-wise misspelling, and also forward any other path info (such as /Blog/foo/bar.html), use this instead:

RedirectMatch 301 ^/[Bb][Ll][Oo][Gg](?<!blog)(/.*)?$ /blog$1

For more options, there are full .htaccess generators available.

Or you can use ModRewrite-based rules for maximum flexibility, but it's probably overkill.



来源:https://stackoverflow.com/questions/4037467/301-redirect-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!