0

我已将新网站上传到 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 文件来重定向对旧 URL 的所有调用:

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)工作正常。

最后一个重定向(根 index.html 到根 index.htm)工作正常。

所有其余的都会导致 404 错误。:-(

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

有谁知道发生了什么?

非常感谢您的时间。

4

1 回答 1

0

终于找到了一个比我预期的效果更好的单行重写。

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

希望这可以帮助某人。

于 2012-11-12T23:20:01.057 回答