0

我正在尝试使用以下代码将所有扩展名为 .php 的页面重定向到 .html:

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.*)\.php$ /rules/$1.html [R=301,L]

RewriteRule ^([^\.]+)\.html$ /rules/$1.php [NC,L]

但收到错误“此网页有重定向循环”

4

2 回答 2

0

您已经完成了 .php 到 .html 的第一次重定向,然后您将 .html 重定向到 .php 重定向,这将递归重定向。

制作这样的代码。这会将 .php 重定向到 .html 文件。

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.php$ /rules/$1.html [R=301,L]
于 2013-09-23T09:01:12.293 回答
0

用这个替换你的代码:

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]
于 2013-09-23T11:31:14.010 回答