这是我的apache配置:
DocumentRoot "/www/public"
<Directory "/www/public">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAlias www.domain.com domain.com
DocumentRoot /www/public
ServerName www.domain.com
</VirtualHost>
<VirtualHost *:80>
ServerAlias www.domain.co.uk domain.co.uk
DocumentRoot /www/public
ServerName www.domain.co.uk
</VirtualHost>
这是我的htaccess的样子:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [NC,L,QSA]
</IfModule>
如果我访问www.domain.com
,domain.com
或www.domain.co.uk
,一切正常。但是,当我访问domain.co.uk
时,它无法正确重定向到www.domain.co.uk
。好像co.uk
请求似乎没有读取我的htaccess。
答案 0 :(得分:0)
这是由于www
添加规则中使用的正则表达式。将其更改为:
RewriteCond %{HTTP_HOST} ^[^.]+\.(?:[^.]+|co\.uk)$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
确保在测试此更改之前清除浏览器缓存。
答案 1 :(得分:0)
解决方案是改变HTACCESS:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
要
RewriteCond %{HTTP_HOST} (^[^.]+\.[^.]+$|^[^.]+\.co\.uk$)