简体   繁体   English

.htaccess无法重定向首页

[英].htaccess not redirecting home page

Here is my .htaccess on a Linux system: 这是我在Linux系统上的.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]

Everything works as it should; 一切都按预期进行。 www is added to non-www requests and a trailing slash is added. 将www添加到非www请求中,并添加斜杠。 However when visiting www.website.com (which is added as a parked domain on cPanel) the user is NOT redirected to www.website.co.uk 但是,当访问www.website.com(在cPanel上作为托管域添加)时,用户不会重定向到www.website.co.uk

If the visit website.com (note no www) then they ARE redirected. 如果访问website.com(注意没有www),则会将其重定向。

What do I need to add/change in .htaccess? 我需要在.htaccess中添加/更改什么?

Have your rules like this: 有这样的规则:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM