RedirectMatch 301 仅适用于 html 文件
我需要对我的网站的所有以 .html 结尾的页面进行批量 301 重定向。我希望将所有旧的 .html 文件移动到子文件夹 ir 中。
RedirectMatch 301 (.*)\.html$ http://www.domain.com/folder/$1.html
当我添加此内容并刷新浏览器时,我在网址后得到大量文件夹/文件夹/文件夹,即
domain.com/folder//folder/folder/folder.....
有什么想法可能是错误的吗?
如果您能提供帮助,谢谢
I need to do a mass 301 Redirect for all pages ending with .html for my site. I am looking to move all the old .html files to a sub-folder ir.
RedirectMatch 301 (.*)\.html$ http://www.domain.com/folder/$1.html
When I add this and refresh the browser I get a ton of folder/folder/folder now after the url ie
domain.com/folder//folder/folder/folder.....
Any ideas what could be wrong?
Thanks if you can help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是,“folder/foo.html”也匹配 RedirectMatch 的条件,并且文件夹被再次附加(一次又一次......)
因此您可能需要这样的东西(未经测试):
RewriteCond 应该检查URI 不以 /folder 开头,并且仅当满足此条件时,才会检查 RewriteRule。
不幸的是,我目前没有任何可用的 Apache 安装来测试此类内容,因此您可能必须自己尝试。但我希望你明白了。
The problem is, that 'folder/foo.html' also matches the condition of the RedirectMatch and folder is appended again (and again, and again ...)
Therefore you probably need something like this (untested):
The RewriteCond should check that the URI doesn't start with /folder and only if this condition is met, the RewriteRule will be checked.
Unfortunately I haven't any Apache installation available at the moment for testing such things, so you will probably have to try it on your own. But I hope you got the idea.
如果您的旧 html 文件位于根目录中,我建议如下:
If your old html files are in the root, I would suggest the following: