重定向循环URL重写
我将所有的.php扩展名重定向到.html,但我遇到了循环问题。重定向循环URL重写
例如,来自:
-mywebsite.com/country/france-php/paris.php
到
-mywebsite.com/country/france-php/paris.html
这里是我的.htaccess:
RewriteEngine On
RewriteBase/
RewriteRule (.+)\.php$ $1.html [R=301,L]
RewriteRule (.+)\.html$ $1.php [L]
FallbackResource /index.php
当重定向侦探分析,我得到很多的重定向:
-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} \ /+([^\?\ ]+)\.php([^\?\ ]*)
RewriteRule^%1.html%2 [L,R=301]
RewriteCond %{DOUMENT_ROOT}/$1.php -f
RewriteRUle ^(.+)\.html(?:(/.*)|)$ $1.php$2 [L]
问题在于重写引擎循环并且您的两条规则互相覆盖。通过添加一些条件,您可以防止这种情况。
工作正常:-mywebsite.com/country/france-php/paris.php和-mywebsite.com/country/france-fcret/但不是-mywebsite.com/country/france-php/ –
@IssamHmz看到编辑 –
感谢很多工作 –
你可以用这种方式试试你的规则。
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/ –
工作正常:-mywebsite.com/country/france-php/paris.php和-mywebsite.com/country/france-fcret/但不-mywebsite.com/country/france-php/ –
@IssamHmz“mywebsite.com/country/france-php /'应该发生什么? – hjpotter92
内法国的PHP文件中的index.php所以它必须打开它,但你的解决方案不会打开它只是文件作为法国-XRF法国-fff打开 –