2017-10-19 49 views
1

我在基於codeigniter的web應用中添加了從非www到www的強制重定向。Codeigniter從non-www重定向到www時刪除index.php

這樣做後,它工作正常,但它顯示一個額外的index.php我需要刪除的URL。

這裏是我的網址:http://www.testprofile.com(工作正常)

這裏的問題引起的:

https://testprofile.com/result/184/1103511096450940jawadamin(非WWW網站,它會自動添加WWW)

打開上述網址重定向到www,但也會在應該刪除的URL中添加一個額外的index.php。

,這裏是我的.htaccess準則

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
RewriteCond %{HTTP_HOST} ^testprofile.com [NC] 
RewriteRule ^(.*)$ https://www.testprofile.com/$1 [L,R=301] 
</IfModule> 

請幫我刪除這個惱人的index.php

感謝,

+0

嘗試一些htaccess的https://github.com/tasmanwebsolutions/htaccess_for_codeigniter – user4419336

+0

@ wolfgang1983我已經嘗試過的,沒有運氣 –

+0

嘗試切換規則的地方:只是'RewriteEngine敘述On'線後,最後兩行剪切和粘貼。但是你也需要在條件行中像'^ testprofile \ .com'那樣轉義。 – Tpojka

回答

1

你錯過了逃避的改寫條件右手邊點線。它應該像

RewriteCond %{HTTP_HOST} ^testprofile\.com [NC] 

或在你的整個例如

<IfModule mod_rewrite.c> 
RewriteEngine On 
#If in root of web server you can use next line or set it appropriate according to location on server 
#RewriteBase/

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

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

如果點沒有被反斜槓字符阿帕奇保存讀它作爲通配符。您可以在this page上找到一些有用的提示。您可以檢查useful .htaccess snippets here

+0

我已經嘗試過幾天,它按預期工作。再次感謝 :) –