2017-05-01 41 views
1

當我去如何從WWW到非www的.htaccess刪除index.php文件重定向

www.example.co/courses 

我重定向到

https://example.co/index.php/courses 

我想重定向到

https://example.co/courses 

我試過的東西

這是我.htaccess文件的時刻:

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

如何刪除重定向的URL的一部分/index.php/

回答

1

你有你的外部重定向在錯誤的地方。他們需要在之前內部重寫(在您的前控制器之前)。例如:

RewriteEngine On 

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

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

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

如果內部重寫,則請求被改寫爲/index.php/...然後把它變成了外部重定向(重寫過程中的循環.htaccess後有你的外部重定向,所以它只被改寫爲index.php在第一個循環中)。

+1

哇,這確實很有道理。謝謝你教我新東西! –

相關問題