.htaccess中的301重定向是否需要按照优先级顺序排列? [英] Do 301 redirects in .htaccess need to be in a priority order?

查看:77
本文介绍了.htaccess中的301重定向是否需要按照优先级顺序排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个重新开发的网站,URL完全不同。我有数百个或301个要执行的操作(原始URL太长了-我不知道为什么),并且得到一些有趣的结果,其中一些重定向正在发生,而另一些正在重定向,但指向奇怪的URL。我想知道是否需要输入特定的301订单。例如:

I have a site which has been redeveloped and the URLs are totally different. I've hundreds or 301 to do (the original URLs many were very long - I have no idea why) and I'm getting some funny results where some redirects are happening and others are redirecting, but to odd URLs. I was wondering if there is a specific order 301's need to go in. For example:

redirect 301 /News/Smart-Site-Waste-Management.aspx http://...
redirect 301 /News/tabid/96/tagid/68/damaged-doors.aspx http://...
redirect 301 /News/tabid/96/EntryId/91/Smart-Site-Waste-Management.aspx http://...
redirect 301 /News/tabid/96/EntryId/156/Plastic-Surgeon-hits-the-headlines.aspx http://...
redirect 301 /News/RepairoftheWeek/tabid/194/tagid/78/Gallery/RepairoftheWeek/tabid/194/EntryId/221/Scratched-laminate-floor-repair.aspx http://...

所以我的实际问题是,较小的网址(目录级别较少的网站)按此顺序降低,而更具体的URL越高?我的直觉告诉我,如果将其设置为上述设置,那么所有这些URL都将直接指向FIRST中指定的新链接,因为它们都以 News /开头。这是我在实践中看到的。

So my actual question is, should the "smaller" urls (the ones with less directory levels) be lower down this order and the more specific URLs be higher? My instinct tells me that if it's set as above, all those URLs will direct to the new link specified in the FIRST as they all start with "News/". This is what I am seeing in practice.

推荐答案

您需要将最具体的放在顶部,而最不具体的放在顶部底部。另外,请确保在每个重定向规则之后暂停使用[L]的处理,以确保apache找到匹配的规则后不再处理其他重写规则。

You need to place the most specific at the top and the least specific at the bottom. Also, make sure you're halting processing using [L] after each redirect rule to make sure apache doesn't process additional rewrite rules after it has found a rule that matches.

您可以发布您的.htaccess文件吗?

Could you please post your .htaccess file?

这篇关于.htaccess中的301重定向是否需要按照优先级顺序排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆