重定向301 htaccess仅适用于斜杠Laravel

时间:2015-10-13 06:26:40

标签: apache .htaccess laravel redirect laravel-4

我的重定向问题。

我想将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>

Digibaj.com

有什么想法吗?!

1 个答案:

答案 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]

确保在清除浏览器缓存后对其进行测试。