2013-04-01 87 views
1

在.htaccess中我看到如何重寫/index.html指向主域:使用HTACCESS重寫index.html並將http://site.com重定向到http://www.site.com

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

+0

也許這可以幫助http://stackoverflow.com/questions/1 5723942/rewriting-an-apache-redirect-rule/15724022#15724022 – ncm

回答

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] 
+0

謝謝!你知道如何讓你的代碼重定向http://www.mycustomcloset.com/index.html到http://www.mycustomcloset.com嗎? –

+0

@JayFrostWebDesign請檢查我的更新!只是不要忘記接受一個確切的答案來通知觀衆。 – 5ervant

+1

是的,這是訣竅!謝謝 –