将非www重定向到www(不包括子域)



首先,请不要将这个问题标记为重复,因为我已经尝试了所有其他答案,但没有人适合我。我有一个名为account.domain.com的子域,这是我的.htaccess:中的代码

RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+.[^.]+$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

我想将访问从domain.com重定向到www.domain.com,这很好。当我访问子域account.subdomain.com时,问题出现了,它重定向到www.account.subdomain.com/account/.php。。。我不知道为什么。

我测试了很多不同的代码,但得到了相同的结果。我的网站托管在Hostinger.es.的免费帐户中

如果您只想以主域为目标,请使用:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

最新更新