将www和index.html重定向到根目录非www.htaccess

将www和index.html重定向到根目录非www.htaccess,.htaccess,redirect,no-www,.htaccess,Redirect,No Www,我想在.htaccess文件中制定一条规则,重定向我的www.example.com和 www.example.com/index.html至example.com 谢谢创建一个.htaccess文件。并加上: #Force non-www: RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.YOURDOMAIN\.com [NC] RewriteRule ^(.*)$ http://YOURDOMAIN.com/$1 [L,R=301] 您可以将

我想在.htaccess文件中制定一条规则,重定向我的www.example.com和 www.example.com/index.html至example.com


谢谢创建一个.htaccess文件。并加上:

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

您可以将这两个需求合并到一个规则中,如下所示:

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]

这应该可以无缝地工作

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

RewriteRule^index\.html$/[R=301,L]RewriteRule^(.*)/index\.html$/$1/[R=301,L]RewriteEngine在RewriteBase/RewriteCond%{HTTP_HOST}^www\.(.*)$[NC]RewriteRule^(.*)$HTTP://%1/$1[R=301,L]谢谢,它在非www上运行良好,但是它仍然缺少从www.example.com/index.html到example.com的重定向