1
我有一个子文件夹中的所有静态HTML文件重定向到新的位置(旧网站的Drupal的版本):重定向一个子文件夹在同一文件中的所有文件到一个新的服务器
oldsite.net/topfolder/subx => newsite.net/subx
但并不是所有文件都在新网站上存在。 丢失的文件应该被重定向到主页面,在新的子文件夹
用一个例子(请备注目标网址没有名“.html”扩展名):
oldsite.net/topfolder/subx/file1.html redirect to newsite.net/subx/file1
oldsite.net/topfolder/subx/file2.html redirect to newsite.net/subx/file2
和
oldsite.net/topfolder/subx/missing1.html redirect to newsite.net/subx/mainpage
oldsite.net/topfolder/subx/missing2.html redirect to newsite.net/subx/mainpage
根的.htaccess,我可以写为每个文件类似的东西:
redirect 301 /topfolder/subx/file1.html http://www.newsite.net/subx/file1
和丢失的文件
redirect 301 /topfolder/subx/missing1.html http://www.newsite.net/subx/mainpage
但是随着越来越多的300个文件,它是一个大量的工作。
我不太擅长重写规则,我试图编写一个规则,但它似乎不工作。
这应该对现有的文件工作(我没喷试了一下):
RewriteRule /topfolder/subx/^ (.*)\.html$ http://www.newsite.net/subx/$1 [R=301,L]
但是对于丢失的文件?上述规则是否正确?
有什么建议吗? 谢谢你的回复。
这绝对是一个好主意,但在新网站上,我希望拥有自己的404页面。 (我的主页是“subx”子文件夹的主页...我的帖子中不太清楚) – gingo 2013-02-27 18:12:24
好的,现在请看我的编辑答案。 – anubhava 2013-02-27 19:02:49
它在我的本地服务器上工作,但不在共享生产服务器上。我不知道为什么,只是没有应用oldsite的规则(但是其他规则可行,即mod_rewrite处于活动状态)。无论如何谢谢(也许我会在每个单一文件上使用重定向301)。 – gingo 2013-02-28 06:49:09