【发布时间】:2010-12-27 01:17:15
【问题描述】:
如何编写将访问者重定向到域www.mydomain.com/ 到www.mydomain.com/index.html 的重写规则?
【问题讨论】:
标签: apache unix .htaccess redirect webserver
如何编写将访问者重定向到域www.mydomain.com/ 到www.mydomain.com/index.html 的重写规则?
【问题讨论】:
标签: apache unix .htaccess redirect webserver
所以您想将 nothing (^$) 重定向到 index.html?然后看起来像
RewriteRule ^$ index.html [L]
如果您想避免 两者 / 和 /index.html 被搜索机器人索引,然后添加 R=301 使其成为 permanent redirect 而不是 temporary redirect (302 ,这是默认值)。这将让机器人只索引/index.html。
RewriteRule ^$ index.html [R=301,L]
【讨论】:
BalusC 所说的 - 但请考虑您是否真的要重定向它们。当浏览器请求/ 时,像大多数服务器一样只提供index.html 不是更好吗?这是到服务器的额外往返,没有任何好处,只会使 URL 更长。这是1990年代。 :)
【讨论】:
一种方法是将您的 index.html 放在另一个文件夹中,例如: domain.com/welcome/index.html 并从您的 CPanel 执行 R301。 这是一个字面意思,但它对我有用。有同样的问题。
【讨论】:
上面可能有错误吗?它对我不起作用,将我重定向到/index.html 中的一个很长的文件路径结尾
对我有用的代码是:
# These two lines redirect the root to index.html.
RewriteRule ^$ /index.html [R=301,L]
RewriteRule ^/$ /index.html [R=301,L]
我在.htaccess redirect root to index.php找到了这个解决方案
【讨论】: