我想重定向以下内容:
http://www.mywebsite.com/monkey
should become
http://www.mywebsite.com/chimpansee
和
http://www.mywebsite.com/monkey/index.html
should become
http://www.mywebsite.com/chimpansee/index.html
以下代码适用于第二种情况(使用index.html)。如何在两种情况下都可以使用?
RewriteCond %{THE_REQUEST} ^GET\ /monkey/
RewriteRule ^monkey/(.*) /chimpansee/$1 [L,R=301]
此一条规则应涵盖以下内容:
RewriteRule ^monkey(/.*)?$ /chimpansee$1 [R=301,L]
请注意,默认情况下,重定向也会执行此类操作,例如
Redirect 301 /monkey/ /chimpansee/
并且避免使用mod_rewrite,根据该指令的位置(即conf或htaccess),可能更可取。
要将其限制为仅GET请求(如您的代码),可以使用REQUEST_METHOD:
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteRule ^monkey(/.*)?$ /chimpansee$1 [R=301,L]
有关可在重写条件中使用的方便的环境变量列表,请参见http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句