2014-04-23 21 views
0

我現在有這在我的.htaccess:CodeIgniter的URL/URI關於WWW CNAME和index.php文件

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

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

當我在域名不帶www前綴鍵入:

[我鍵入URL BAR =>它最終變得]

example.com => http://www.example.com/ == GOOD! 

如果我輸入:

www.example.com/register => http://www.example.com/register == GOOD! 

但是當我鍵入:

example.com/register => http://www.example.com/index.php/register == BAD! 

如何刪除所有角落情況下的index.php部分? (特別是最後一個......)

回答

0

試試這個代碼

# First add the www to URL 
RewriteCond %{HTTP_HOST} ^example.com$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] 

# The remove the index.php from URL 
RewriteCond $1 !^(index\.php|ref_doc|media|images|css|js|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

的順序很重要,我想