1

在 .htaccess 中,我看到如何重写/index.html以指向主域:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*\/index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ "/$1" [R=301,L]

我也了解 .htaccess 如何防止网站在 WWW 下被索引,而没有它

RewriteEngine on
rewritecond %{http_host} ^mycustomcloset.com [nc]
rewriterule ^(.*)$ http://www.mycustomcloset.com/$1 [r=301,nc]

但是你如何同时做到这两点呢?

换句话说,我希望mycustomcloset.commycustomcloset.com/index.html都指向http://www.mycustomcloset.com

4

1 回答 1

1

我不理解您问题的第一个代码,但是您仍然可以尝试这个:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R,NE]

现在,如果您还想将mycustomcloset.com/index.htmlwww.mycustomcloset.com/index.html重定向到www.mycustomcloset.com ,那么您可以试试这个:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R,NE]

RewriteRule ^index.html$ http://www.mycustomcloset.com [R,NE]
于 2013-04-02T05:36:00.547 回答