2016-08-20 37 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]