.htaccess在文件夹/文件名更改之间重定向的问题

时间:2012-11-12 14:33:03

标签: .htaccess redirect

我已将新网站上传到GoDaddy共享Linux主机帐户。之前的网站使用了这种结构:

Root
----/about (folder)
----/maintenance (folder)
----/services (folder)
...

这些文件夹中的每一个都有一个index.html文件。

新的网站结构不同:

Root
.htaccess
about.htm (file in root)
maintenance.htm (file in root)
services.htm (file in root)
...

我上传了此.htaccess文件,以重定向对旧网址的所有调用:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domainname.com
RewriteRule (.*) http\:\/\/www\.domainname\.com/$1 [R=301,L]

rewritecond %{HTTP_HOST} ^www.domainname.com$
rewriterule ^services\/index\.html "http\:\/\/www\.domainname\.com\/services\.htm" [R=301,L]

rewritecond %{HTTP_HOST} ^www.domainname.com$
rewriterule ^why_wood\/index\.html "http\:\/\/www\.domainname\.com\/why-wood\.htm" [R=301,L]

rewritecond %{HTTP_HOST} ^www.domainname.com$
rewriterule ^about\/index\.html "http\:\/\/www\.domainname\.com\/about\.htm" [R=301,L]

rewritecond %{HTTP_HOST} ^www.domainname.com$
rewriterule ^what-to-expect\/index\.html "http\:\/\/www\.domainname\.com\/faq\.htm" [R=301,L]

rewritecond %{HTTP_HOST} ^www.domainname.com$
rewriterule ^maintenance\/index\.html "http\:\/\/www\.domainname\.com\/maintenance\.htm" [R=301,L]

rewritecond %{HTTP_HOST} ^www.domainname.com$
rewriterule ^contact\/index\.html "http\:\/\/www\.domainname\.com\/contact\.htm" [R=301,L]

rewritecond %{HTTP_HOST} ^www.domainname.com$
rewriterule ^index\.html "http\:\/\/www\.domainname\.com\/index\.htm" [R=301,L]

使用位于stepforth的服务器标头检查工具,我检查了重定向是否正常。这是回来的:

**Input**
domainname.com/about/index.html
**Output**
www.domainname.com/about.htm/index.html (**expected** www.domainname.com/about.htm)

第一个重定向(非www到www)工作正常。

最后一次重定向(root index.html到root index.htm)运行正常。

所有其他结果都会导致404错误。 : - (

我已经看了3个小时,但还没有找到任何信息,甚至暗示了重写中要改变的内容。只有7个旧的URL,但它是我需要修复的两个问题中的第一个,然后我才能完成它。

有没有人知道发生了什么?

非常感谢你的时间。

1 个答案:

答案 0 :(得分:0)

最后发现一行重写比我预期的更好。

作者的示例是将不存在的favicon请求的URL重定向回站点根目录中的单个现有favicon。该文章在Perishable Press

希望这有助于某人。

相关问题