Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Php htaccess重定向索引,无文件扩展名_Php_Apache_.htaccess_Http Status Code 301 - Fatal编程技术网

Php htaccess重定向索引,无文件扩展名

Php htaccess重定向索引,无文件扩展名,php,apache,.htaccess,http-status-code-301,Php,Apache,.htaccess,Http Status Code 301,我刚碰到这个。我正在运行wordpress网站,我想将此www.dentistcostamesads.com/index重定向到www.dentistcostamesads.com。我下面的代码不起作用 # Permanent URL redirects RewriteEngine On RewriteBase / Redirect 301 /index http://www.dentistcostamesadds.com 正如您在下面看到的,只有/索引没有扩展名不起作用。为什么? Redir

我刚碰到这个。我正在运行wordpress网站,我想将此www.dentistcostamesads.com/index重定向到www.dentistcostamesads.com。我下面的代码不起作用

# Permanent URL redirects
RewriteEngine On
RewriteBase /
Redirect 301 /index http://www.dentistcostamesadds.com
正如您在下面看到的,只有/索引没有扩展名不起作用。为什么?

Redirect 301 /index.php http://www.dentistcostamesadds.com WORKS
Redirect 301 /index.html http://www.dentistcostamesadds.com WORKS
Redirect 301 /index.aspx http://www.dentistcostamesadds.com WORKS
Redirect 301 /home http://www.dentistcostamesadds.com WORKS
Redirect 301 /home.html http://www.dentistcostamesadds.com WORKS
Redirect 301 /index http://www.dentistcostamesadds.com DOESN'T WORK

以下内容将实现此目的:

RewriteEngine On
RewriteRule ^index?$                               /
这表示将请求重定向到www.(…)/将索引重定向到www.(…)


其中www.(…)是域。

这是因为
重定向
指令自动将URI的其余部分附加到目标。因此,如果您只有:

Redirect 301 /abc http://domain.com/xyz
这意味着对
/abc1234
的请求将被重定向到
http://domain.com/xyz1234
,并且
/abc/foo/bar
被重定向到
http://domain.com/xyz/foo/bar
。因此,如果要重定向所有这些内容,可以尝试使用正则表达式:

RedirectMatch 301 ^(index|home)(\.php|\.html|\.aspx)?$ http://www.dentistcostamesadds.com