Reputation: 368
I have a problem with my redirection.
i wanna redirect domain.ir to domain.com ok all fine but when
I wanna all request from domain.ir redirect to domain.com only work when i finish urls with slash
domain.ir/wiki/ ---> domain.com/wiki
but
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>
Any idea?!
Upvotes: 3
Views: 858
Reputation: 785156
Re-factor and reorder your rules like this:
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]
Make sure to test it after clearing your browser cache.
Upvotes: 2