apache 将域重定向到 index.html 的 Htaccess 规则
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1911417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Htaccess rule to redirect domain to index.html
提问by TheFlash
How do I write a rewrite-rule that redirects visitors to the domain www.mydomain.com/to www.mydomain.com/index.html?
我怎样写一个重写规则重定向访问者到域www.mydomain.com/来www.mydomain.com/index.html?
回答by BalusC
So you want to redirect nothing(^$) to index.html? That would then look like
所以你想什么都不重定向( ^$) 到index.html? 那看起来像
RewriteRule ^$ index.html [L]
If you want to avoid boththe /and /index.htmlbeing indexed by search bots, then add R=301to make it a permanentredirectrather than a temporaryredirect(302, which is the default). This would let the bots only index the /index.html.
如果你想避免两者的/和/index.html被搜索机器人被编入索引,然后再加R=301以使它成为一个永久重定向,而不是一个临时的重定向(302,这是默认值)。这将让机器人只索引/index.html.
RewriteRule ^$ index.html [R=301,L]
回答by EMP
What BalusCsaid - but consider whether you really want to redirect them. Wouldn't it be better to just serve index.htmlwhen 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. :)
什么BalusC说-但考虑是否真的要对它们进行重定向。像大多数服务器一样,只index.html在浏览器请求时提供服务不是更好/吗?这是到服务器的额外往返,没有任何好处,只会使 URL 更长。这太 1990 年代了。:)
回答by Dejan Mur
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.
一种方法是将您的 index.html 放在另一个文件夹中,例如:domain.com/welcome/index.html 并从您的 CPanel 执行 R301。这是一个词,但它对我有用。有同样的问题。
回答by Islam Tawfik
Is it possible there's a mistake above? It didn't work for me, redirecting me to a very long filepath endingin /index.htmlThe code that worked for me is:
有没有可能上面有错误?它没有对我来说有效,重定向我到一个很长的文件路径结束在/index.html这工作对我来说是代码:
# 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
我在.htaccess redirect root to index.php找到了这个解决方案

