Mod rewrite 重定向循环URL重写

Mod rewrite 重定向循环URL重写,mod-rewrite,url-rewriting,url-redirection,friendly-url,Mod Rewrite,Url Rewriting,Url Redirection,Friendly Url,我将所有的.php扩展重定向到.html,但我遇到了一个循环问题 例如,来自: -mywebsite.com/country/france-php/paris.php 到 这是我的.htaccess: RewriteEngine On RewriteBase / RewriteRule (.+)\.php$ $1.html [R=301,L] RewriteRule (.+)\.html$ $1.php [L] FallbackResource /index.php 当使用redi

我将所有的.php扩展重定向到.html,但我遇到了一个循环问题

例如,来自:

-mywebsite.com/country/france-php/paris.php

这是我的.htaccess:

RewriteEngine On
RewriteBase /    
RewriteRule (.+)\.php$ $1.html [R=301,L]
RewriteRule (.+)\.html$ $1.php [L] 
FallbackResource /index.php
当使用redirection detective进行分析时,我得到许多重定向到:

-mywebsite.com/country/france-php/paris.html

根据收到的原始请求执行第一次重定向:

RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.php
RewriteRule ^ /%1.html [R=301,L]

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

要将
index.php
加载为
index.html
,您可以在顶部添加以下重写:

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} ^(.*)/$
RewriteRule ^ %1/index.php [R=301,L]
尝试:


问题是重写引擎循环,而您的两条规则一直在互相覆盖。通过添加一些条件,您可以防止这种情况。

您可以通过这种方式尝试您的规则

RewriteEngine On
RewriteBase /    
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /(.+)\.php
RewriteRule ^ %1.html? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)\.html$ $1.php [L] 

适用于:-mywebsite.com/country/france-php/paris.php和-mywebsite.com/country/france-fcret/但不适用于-mywebsite.com/country/france-php/works适用于:-mywebsite.com/country/france-php/paris.php和-mywebsite.com/country/france-fcret/但不适用于-mywebsite.com/country/france-php/@IssamHmz应该发生什么
mywebsite.com/country/france php/
?在法国php文件中有一个index.php,因此它必须打开它,但在您的解决方案中,它不会只打开它的文件,因为法国xrf france-fff是打开的:-mywebsite.com/country/france-php/paris.php和-mywebsite.com/country/france-fcret/但不适用于-mywebsite.com/country/france-php/
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.php([^\?\ ]*)
RewriteRule ^ %1.html%2 [L,R=301]

RewriteCond %{DOUMENT_ROOT}/$1.php -f
RewriteRUle ^(.+)\.html(?:(/.*)|)$ $1.php$2 [L]
RewriteEngine On
RewriteBase /    
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /(.+)\.php
RewriteRule ^ %1.html? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)\.html$ $1.php [L]