我必须将子文件夹的所有静态 HTML 文件重定向到新位置(旧站点的 drupal 版本):
oldsite.net/topfolder/subx => newsite.net/subx
但新站点上不再存在所有文件。丢失的文件应重定向到新子文件夹中的主页
举个例子(请注意目标 URL 没有“.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]
但是丢失的文件怎么办?上面的规则对吗?
有什么建议吗?谢谢你的回复。