使用HTACCESS重写index.html并将http://site.com重定向到http://www.site.com

时间:2013-04-01 22:41:44

标签: apache .htaccess redirect

在.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.com mycustomcloset.com/index.html 指向 http://www.mycustomcloset.com

1 个答案:

答案 0 :(得分: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.html www.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]