2015-01-17 55 views
1

這是我在Linux系統上的.htaccess:的.htaccess不重定向主頁

ErrorDocument 401 ./error/ 
ErrorDocument 403 ./error/ 

RewriteEngine on 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$ 

RewriteRule ^(.*)$ http://www.website.co.uk/$1/ [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?page=$1 [QSA] 

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

一切正常,因爲它應該; www被添加到非www請求中,並添加了一個結尾的斜槓。然而,當訪問www.website.com(這是作爲一個停放的cPanel域),用戶不會重定向到www.website.co.uk

如果訪問website.com(注意不是www),那麼他們是重定向。

我需要在.htaccess中添加/更改什麼?

回答

1

讓你的規則是這樣的:

ErrorDocument 401 ./error/ 
ErrorDocument 403 ./error/ 

RewriteEngine on 
RewriteBase/

# if not www.website.co.uk then redirect to it 
RewriteCond %{HTTP_HOST} !^www\.website\.co\.uk$ [NC] 
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule ^(.*)$ http://www.website.co.uk/$1/ [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]