麻烦重定向文件夹中的所有网页的页面在根目录根目录、重定向、麻烦、页面

2023-09-02 00:37:03 作者:恨天

我已经搜查,尝试了各种例子,没有,不是创造的重定向声明一个明确的列表似乎工作等。 最大的问题我是这样的,虽然我有机会部署网页的网站,我没有访问任何虚拟主机控制面板 - 站点访问被继承,而且到现在为止它已经很好,但我认为这是无论是运行旧版本的Apache,或改写不准规则。 Anywa,多年来,该网站已经改了好几次,并注册该网站与谷歌Web工具后,我发现,给了抓取错误页面的列表,因此创建一个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 正如你所看到的,我有一些情况下,文件夹名称为骆驼,别人低,等情况下,有一个HTM,并列出在抓取错误日志中同名的HTML文件。 所有我想要做的是,在上面的例子中,从重定向/挑战/和/挑战/于lsr_history.html,所有的网页,但在/质询/赞助商/所有文件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

推荐答案

我不会刻意寻找匹配字符串这种东西里面的情况下,如果我能避免它 - 你试过只指定 RedirectMatch 以小写,并追加 [NC] 每一行的结束? (会告诉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)

如果您有类似的格式化重写的集合,为什么不将它们组合与一个特定组的每个规则?这样,你可以包括,例如,其中一个子目录有一个规则,并用一个子目录之一,另一条规则的所有传入的URL的所有传入的URL。如果不出意外,它可以帮助简化查看.htaccess文件:)

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

*(把所有的东西,我建议用大剂量的盐,我仍然掌握黑难懂的mod_rewrite的自己)*

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