2014-10-21 106 views
0

我刚碰到这个。我正在运行一个wordpress网站,我想将这个www.dentistcostamesadds.com/index重定向到www.dentistcostamesadds.com。我的下面的代码不起作用。htacess重定向索引,没有文件扩展名

# 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 

回答

1

这是因为Redirect指令自动将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 
0

下面将做的伎俩:。

RewriteEngine On 
RewriteRule ^index?$        /

这是说将请求重定向到www(...)/索引WWW(...)

其中WWW。 (...)是域。