Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache Htaccess规则将域重定向到index.html_Apache_Unix_.htaccess_Redirect_Webserver - Fatal编程技术网

Apache Htaccess规则将域重定向到index.html

Apache Htaccess规则将域重定向到index.html,apache,unix,.htaccess,redirect,webserver,Apache,Unix,.htaccess,Redirect,Webserver,如何编写重写规则,将访问者重定向到域www.mydomain.com/到www.mydomain.com/index.html?所以您不想将任何内容(^$)重定向到index.html?那看起来就像 RewriteRule ^$ index.html [L] 如果您希望避免搜索机器人对/和/index.html进行索引,请添加R=301,使其成为一个而不是一个(302,这是默认值)。这将使机器人程序只对/index.html进行索引 RewriteRule ^$ index.html [R=3

如何编写重写规则,将访问者重定向到域
www.mydomain.com/
www.mydomain.com/index.html

所以您不想将任何内容(
^$
)重定向到
index.html
?那看起来就像

RewriteRule ^$ index.html [L]
如果您希望避免搜索机器人对
/
/index.html
进行索引,请添加
R=301
,使其成为一个而不是一个(302,这是默认值)。这将使机器人程序只对
/index.html
进行索引

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

<>强> BaluSc<强> -但是考虑你是否真的想要重定向它们。像大多数服务器一样,当浏览器请求
/
时,只提供
index.html
不是更好吗?这是一个额外的往返服务器没有收益,只是使网址更长。太棒了。:)

一种方法是将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]

我在

看到问题的背景时发现了这个解决方案(默认情况下apache已经这样做了),我认为他只是想摆脱它:)我想要它是因为这个原因: