2016-08-20 134 views
-4

我想在我的.htaccess文件中制定规则,将我的www.example.com和 www.example.com/index.html重定向到示例。 com将www和index.html重定向到root非www .htaccess

谢谢

+0

[通用htaccess的重定向WWW非的可能的复制(http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) –

+0

RewriteEngine On RewriteRule^index \ .html $/[R = 301,L] 重写规则^(。*)/索引\ html的$/$ 1/[R = 301,L] RewriteEngine叙述在 RewriteBase/ 的RewriteCond%{HTTP_HOST}^WWW \。(。*)$ [NC] 重写规则^(。*)$ http://%1/$ 1 [R = 301,L] –

回答

0

创建一个.htaccess文件。并补充一点:

#Force non-www: 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^www\.YOURDOMAIN\.com [NC] 
RewriteRule ^(.*)$ http://YOURDOMAIN.com/$1 [L,R=301] 
+0

感谢它对于非www的工作正常,但它仍然缺少从www.example.com/index.html到示例的重定向。 COM –

1

您可以在一个单一的规则是这样结合了要求:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^www\. [NC,OR] 
RewriteCond %{THE_REQUEST} /index\.html[?\s] [NC] 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] 
RewriteRule ^(.*?)(?:index\.html)?$ http://%1/$1 [L,R=301,NE,NC] 
0

thiis应该工作无缝

RewriteCond %{HTTP_HOST} ^www\.sitename\.com [NC] 
RewriteRule ^(.*)$ https://sitename.com/$1 [L,R=301,NC]