我有权利url:example.com/contact.php和我想把这个重定向到假的url example.com/contact/。
如果我
RewriteRule ^contact\.php$ /contact [R=301,L]
RewriteRule ^contact$ /contact\.php [NC,L]这就产生了无穷大的循环。
有可能这样做吗?
发布于 2014-08-13 19:40:18
为此您需要使用THE_REQUEST变量。THE_REQUEST变量表示Apache从浏览器接收到的原始请求,并且在执行某些重写规则后不会被覆盖。此变量的示例值为GET /index.php?id=123 HTTP/1.1。
将此代码放入您的DOCUMENT_ROOT/.htaccess文件中。
RewriteEngine On
RewriteBase /
# external redirect from /contact.php to /contact
RewriteCond %{THE_REQUEST} \s/+(contact)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
# To internally forward from /contact to /contact.php
RewriteRule ^(contact)/?$ $1.php [L,NC]https://stackoverflow.com/questions/25294628
复制相似问题