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 如何实现从index.htm到root的简单301重定向?_Apache_Wordpress_.htaccess_Mod Rewrite_Http Status Code 301 - Fatal编程技术网

Apache 如何实现从index.htm到root的简单301重定向?

Apache 如何实现从index.htm到root的简单301重定向?,apache,wordpress,.htaccess,mod-rewrite,http-status-code-301,Apache,Wordpress,.htaccess,Mod Rewrite,Http Status Code 301,我读过很多关于重定向的参考网站,说实话,我了解的很少 我目前在my.htaccess中有标准WordPress mod_rewrite重定向规则: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php

我读过很多关于重定向的参考网站,说实话,我了解的很少

我目前在my.htaccess中有标准WordPress mod_rewrite重定向规则:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
我的很多推荐人都去了一个旧的URL
http://www.example.com/index.htm
,这会给他们一个错误,我希望他们能够无缝地重定向到
http://www.example.com/
。我相信301重定向是最好的方法


我需要做什么?

我不是100%确定,但我想应该是
RewriteRule^index.htm$/[R=301]
或类似的东西

RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html? [NC]
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]

这将递归地将所有出现的index.html或index.htm转换为目录。

创建一个index.html,其中包含以下代码:

<HTML>
<HEAD>
<META HTTP-EQUIV="refresh" CONTENT="seconds;URL=the-other-url">
</HEAD>
<BODY>
You will be redirected...
</BODY>
</HTML> 

您将被重定向。。。
其中“秒”是重定向之前的延迟持续时间(以秒为单位)。为即时重定向设置“0”


“另一个url”是

当你说“递归”时,你的意思是这将适用于站点内的所有子目录,我想?是的,没错。适用于所有子目录。非常感谢。我意识到我需要把这个规则放在我现有的Wordpress规则之前。这对我来说也很有用。我必须删除/from/$1才能使它在我的配置(Apache 2.4.7)中工作。这不是301重定向,取决于客户端,通常被认为是不好的做法。