2016-08-12 145 views
1

我有我的htaccess文件的問題。它重定向頁面根本就是index.php文件

例如: 如果我使用的URL像http://domain.com/jobs或domain.com/jobs其重定向頁面www.domain.com/index.php
但是,如果使用WWW .domain.com/jobs不會將頁面重定向到其他頁面。
以下是我htaccess - 重定向到另一個頁面

<IfModule mod_rewrite.c> 
     <IfModule mod_negotiation.c> 
      Options -MultiViews 
     </IfModule> 

     RewriteEngine On 

     # Redirect Trailing Slashes... 
     RewriteRule ^(.*)/$ /$1 [L,R=301] 

     # Handle Front Controller... 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteRule^index.php [L] 

    RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] 
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 
</IfModule> 

回答

2

使用htaccess的代碼[L]標誌是去年,它告訴mod_rewrite這一個匹配後停止處理規則的捷徑。

RewriteRule^index.php [L]規則被處理,它將您的請求重定向到index.php,在此之後省略規則。

解決方法是 - 更改規則的順序。它應該看起來像這樣:

<IfModule mod_rewrite.c> 
     <IfModule mod_negotiation.c> 
      Options -MultiViews 
     </IfModule> 

     RewriteEngine On 


    RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] 
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 

     # Redirect Trailing Slashes... 
     RewriteRule ^(.*)/$ /$1 [L,R=301] 

     # Handle Front Controller... 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteRule^index.php [L] 
</IfModule> 

它將被重定向到www.domain.com,然後將執行其他規則檢查。

+0

謝謝@lisectech – Omkar

相關問題