我尝试使用以下代码将所有扩展名为.php的页面重定向到.html:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.php$ /rules/$1.html [R=301,L]
RewriteRule ^([^\.]+)\.html$ /rules/$1.php [NC,L]但是得到一个错误“这个网页有一个重定向循环”
发布于 2013-09-23 17:01:12
你已经做了第一个.php到.html的重定向,然后你做了.html到.php的重定向,所以,这将是重定向的递归。
编写这样的代码。这会将.php重定向到.html文件。
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.php$ /rules/$1.html [R=301,L]发布于 2013-09-23 19:31:14
使用以下代码替换您的代码:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1.html? [R=301,L]
# To internally forward /dir/foo.html to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)\.html?$ /$1.php [L,NC]https://stackoverflow.com/questions/18955151
复制相似问题