将文件夹中的所有页面重定向到根级别的页面时出现问题

发布于 2024-08-12 12:47:52 字数 1434 浏览 2 评论 0原文

我已经搜索、尝试了各种示例,但除了创建明确的重定向语句列表之外,没有其他示例似乎有效。
我遇到的最大问题是,虽然我有权将网页部署到网站,但我无权访问任何网络托管控制面板 - 网站访问权限是继承的,到目前为止一切都很好,但我认为这是要么运行旧版本的 apache,要么不允许重写规则。
Anywa,这些年来,该网站已更改了几次,在使用 Google Webtools 注册该网站后,我发现了出现抓取错误的页面列表,因此创建了一个 HTACCESS 文件来处理这些问题。
多年来,已经有文件夹以驼峰大小写和小写形式部署和命名,因此我想做的就是将文件夹中的所有文件重定向到 .htaccess 文件级别的新文件夹,即
我的 .HTACCESS 目前有 120 行,示例批次如下:
重定向 301 /challenge/stanley_steamer.htm /lsr_history.html
重定向 301 /challenge/stanley_steamer.html /lsr_history.html
重定向 301 /Challenge/index.htm /lsr_history.html
重定向 301 /Challenge/Record.htm /lsr_history.html
重定向 301 /Challenge/Stanley_Steamer.htm /lsr_history.html
重定向 301 /Challenge/Sponsors/Avery_Weigh-Tronix.htm /sponsors.html
重定向 301 /contact/index.html /contact.html
重定向 301 /design/details.html /design.html
重定向 301 /design/index.html /design.html
重定向 301 /Design/Engine-drive_train.htm /design.html
重定向 301 /Design/Rear.htm /design.html
重定向 301 /Design/Home_Page.htm /design.html
重定向 301 /Design/index.htm /design.html
正如您所看到的,我在某些情况下文件夹名称为“camel”,其他情况下为较低名称,在其他情况下,抓取错误日志中列出了同名的 htm 和 html 文件。
在上面的示例中,我想做的就是将所有页面从 /Challenge/ 和 /challenge/ 重定向到 lsr_history.html,但将 /Challenge/Sponsors/ 中的所有文件重定向到 Sponsors.html。
我还有一个巨大的个人团队页面列表,我将其一一列出,每个页面都重定向到新的团队页面。
我尝试过这样的例子:
RedirectMatch 301 ^/[Cc]hallenge/ /challenge.html,但这会返回“错误 404 未找到”。
任何有关如何减少 htaccess 文件以简化此操作的想法或示例将不胜感激。
问候
马丁

I've searched, tried various examples, and none, other than creating an explicit list of redirect statements seems to work.
The biggest issue I have is that, although I have access to deploy web pages to the site, I do not have access to any web hosting control panel - site access was inherited, and until now it's been fine, but I think that it is either running an old version of apache, or rewrite rules are not allowed.
Anywa, over the years, the site has changed several times, and after registering the site with Google Webtools, I found the list of pages that gave crawl errors, so created an HTACCESS file to deal with these.
Over the years, there have been folders deployed and named in camel case and all lower case, and so all I wanted to do was to redirect all files in a folder to the new folder in the .htaccess file level, i.e.
My .HTACCESS currently has 120 lines, and an example batch are as follows:
redirect 301 /challenge/stanley_steamer.htm /lsr_history.html
redirect 301 /challenge/stanley_steamer.html /lsr_history.html
redirect 301 /Challenge/index.htm /lsr_history.html
redirect 301 /Challenge/Record.htm /lsr_history.html
redirect 301 /Challenge/Stanley_Steamer.htm /lsr_history.html
redirect 301 /Challenge/Sponsors/Avery_Weigh-Tronix.htm /sponsors.html
redirect 301 /contact/index.html /contact.html
redirect 301 /design/details.html /design.html
redirect 301 /design/index.html /design.html
redirect 301 /Design/Engine-drive_train.htm /design.html
redirect 301 /Design/Rear.htm /design.html
redirect 301 /Design/Home_Page.htm /design.html
redirect 301 /Design/index.htm /design.html
As you can see, I have some cases where the folder name is camel, others lower, and other cases where there is a htm and an html file of the same name that is listed in the crawl error log.
All I want to do is, in the example above, redirect all pages from /Challenge/ and /challenge/ to lsr_history.html, but all files in /Challenge/Sponsors/ to sponsors.html.
I also have a huge list of individual team pages that I list one by one and each one redirects to the new team page.
I've tried examples like:
RedirectMatch 301 ^/[Cc]hallenge/ /challenge.html, but this returns a 'Error 404 Not found'.
Any ideas or examples of how I can cut down my htaccess file to simplify this will be gratefully received.
Regards
Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

素衣风尘叹 2024-08-19 12:47:52

如果我可以避免这种情况,我就不会费心在匹配字符串中搜索案例 - 您是否尝试过仅以小写形式指定 RedirectMatch 并附加 [NC] 到每一行的末尾? (这将告诉 mod_rewrite 忽略大小写并进行匹配,这可能会节省您一些时间)

如果您有类似格式的重写集合,为什么不将它们分组在一起并为每个重写指定一组特定规则?例如,通过这种方式,您可以使用一条规则覆盖具有一个子目录的所有传入 URL,以及使用另一条规则覆盖具有单个子目录的所有传入 URL。如果没有别的事,它可以帮助简化查看 .htaccess 文件:)

(接受我建议的所有内容,我自己仍在掌握 mod_rewrite 的黑魔法)

I wouldn't bother searching for cases inside the match string for this kind of thing if I could avoid it - have you tried just specifying the RedirectMatch in lowercase, and appending [NC] to the end of every line? (that will tell mod_rewrite to ignore case and match regardless, which may save you some time)

if you have collections of similarly-formatted rewrites, why not group them together with one particular set of rules for each? That way you could cover, for example, all incoming URLs with one subdirectory with one rule, and all incoming URLs with a single subdirectory one with another rule. If nothing else, it could help simplify viewing the .htaccess file :)

(Take everything I suggest with a massive dose of salt, I'm still getting to grips with the black magick of mod_rewrite myself)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文