多余的www被添加到域中

时间:2018-10-12 10:54:58

标签: .htaccess mod-rewrite

我已修改。htaccess文件以强制 https 。现在,我无法再加载我的网站。当我打开它时,它会自动更改为www.www.example.com

我已删除。htaccess文件,但问题仍未解决。

这里是htaccess的缩写代码:

Options All -Indexes 
DirectoryIndex index.php index.htm index.html 

RewriteEngine on 
RewriteBase / 

# Force HTTPS on the subdomains/subdirectories login or admin 
#RewriteCond %{HTTPS} off 
#RewriteCond %{HTTP_HOST} ^(login|admin)\. [NC] 
#RewriteCond %{REQUEST_URI} ^(login|admin)\. [NC,OR] 
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# Force WWW if no subdomain is given 
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

1 个答案:

答案 0 :(得分:0)

这是因为您的htaccess代码不正确。一旦删除,由于浏览器的缓存,您仍然会遇到问题。尝试清除它,然后再试一次,应该没问题。

您的代码的有效版本为:

RewriteEngine on 
RewriteBase / 

# Force HTTPS on the subdomains/subdirectories login or admin 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(login|admin)\. [NC,OR] 
RewriteCond %{REQUEST_URI} ^/(login|admin)/ [NC] 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# Force WWW if no subdomain is given 
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{HTTPS} off [NC,OR]
RewriteCond %{HTTPS}::s on::(s) [NC]
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]