我的重定向问题。
我想将domain.ir重定向到domain.com 确定没问题,但
时我想从domain.ir重定向到domain.com的所有请求仅在我使用斜杠完成网址时才能正常工作
domain.ir/wiki/ ---> domain.com/wiki
但
domain.ir/wiki ---> domain.com/index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{HTTP_HOST} ^www.digibaj.com$ [NC]
RewriteRule ^(.*)$ http://digibaj.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.digibaj.ir$ [NC]
RewriteRule ^(.*)$ http://digibaj.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^digibaj.ir$ [NC]
RewriteRule ^(.*)$ http://digibaj.com/$1 [R=301,L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
有什么想法吗?!
答案 0 :(得分:2)
重新考虑并重新排序您的规则:
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.digibaj\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?digibaj\.ir$ [NC]
RewriteRule ^(.*)$ http://digibaj.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
# Redirect Trailing Slashes for non-directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
确保在清除浏览器缓存后对其进行测试。