RedirectMatch 301 仅适用于 html 文件

发布于 2024-08-25 11:47:51 字数 308 浏览 2 评论 0原文

我需要对我的网站的所有以 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-09-01 11:47:51

问题是,“folder/foo.html”也匹配 RedirectMatch 的条件,并且文件夹被再次附加(一次又一次......)

因此您可能需要这样的东西(未经测试):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*)\.html$ /folder/$1.html [R=301,L]

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):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*)\.html$ /folder/$1.html [R=301,L]

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.

看海 2024-09-01 11:47:51

如果您的旧 html 文件位于根目录中,我建议如下:

RedirectMatch 301 ^([^/]+)\.html$ http://www.domain.com/folder/$1.html

If your old html files are in the root, I would suggest the following:

RedirectMatch 301 ^([^/]+)\.html$ http://www.domain.com/folder/$1.html
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文