Htaccess rule to redirect domain to index.html

送分小仙女□ 提交于 2019-12-18 04:44:05

问题


How do I write a rewrite-rule that redirects visitors to the domain www.mydomain.com/ to www.mydomain.com/index.html?


回答1:


So you want to redirect nothing (^$) to index.html? That would then look like

RewriteRule ^$ index.html [L]

If you want to avoid both the / and /index.html being indexed by search bots, then add R=301 to make it a permanent redirect rather than a temporary redirect (302, which is the default). This would let the bots only index the /index.html.

RewriteRule ^$ index.html [R=301,L]



回答2:


What BalusC said - but consider whether you really want to redirect them. Wouldn't it be better to just serve index.html when the browser requests /, like most servers do? It's an extra round-trip to the server for no gain and just makes the URL longer. It's so 1990s. :)




回答3:


One way is to put your index.html in another folder, for exemple: domain.com/welcome/index.html and do a R301 from your CPanel. It's a wordaround but it worked for me. Have the same issue.




回答4:


Is it possible there's a mistake above? It didn't work for me, redirecting me to a very long filepath ending in /index.html The code that worked for me is:

# These two lines redirect the root to index.html.
RewriteRule ^$ /index.html [R=301,L]
RewriteRule ^/$ /index.html [R=301,L]

I found this solution at .htaccess redirect root to index.php



来源:https://stackoverflow.com/questions/1911417/htaccess-rule-to-redirect-domain-to-index-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!