.htaccess中的301重定向是否需要按优先级顺序排列?

时间:2021-08-24 11:20:19

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:

我有一个已经重新开发的网站,网址完全不同。我有数百或301要做(原始网址很多很长 - 我不知道为什么)我得到了一些有趣的结果,其中一些重定向正在发生,其他重定向,但奇怪的URL。我想知道是否有特定订单301需要进入。例如:

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://...

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.

所以我的实际问题是,“较小的”网址(目录级别较低的网址)是否应该低于此顺序,更具体的网址会更高?我的直觉告诉我,如果设置如上,所有这些URL将指向FIRST中指定的新链接,因为它们都以“新闻/”开头。这就是我在实践中看到的。

2 个解决方案

#1


5  

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.

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

Could you please post your .htaccess file?

你能发布你的.htaccess文件吗?

#2


0  

Order is only important if there are multiple match lines (e.g. if you are also using RedirectMatch or the mod_rewrite RewriteEngine On which can interact with redirect directives.

只有当存在多个匹配行时,顺序才是重要的(例如,如果您还使用RedirectMatch或mod_rewrite RewriteEngine On可以与重定向指令交互。

You will experience a performance hit parsing 100s of rule in an htaccess file, especially if the match rate is now small. If your current URIs do not start with /News, then a good trick is to move all of these redirects to DOCROOT/News/.htaccess as this will only be parsed for URIs /News/.... and hence out of any other URI path.

您将在htaccess文件中体验解析100s规则的性能,特别是如果匹配率现在很小。如果您当前的URI不以/ News开头,那么一个好方法是将所有这些重定向移动到DOCROOT / News / .htaccess,因为这只会针对URI / News / ....进行解析,因此不会出现任何其他URI URI路径。

#1


5  

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.

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

Could you please post your .htaccess file?

你能发布你的.htaccess文件吗?

#2


0  

Order is only important if there are multiple match lines (e.g. if you are also using RedirectMatch or the mod_rewrite RewriteEngine On which can interact with redirect directives.

只有当存在多个匹配行时,顺序才是重要的(例如,如果您还使用RedirectMatch或mod_rewrite RewriteEngine On可以与重定向指令交互。

You will experience a performance hit parsing 100s of rule in an htaccess file, especially if the match rate is now small. If your current URIs do not start with /News, then a good trick is to move all of these redirects to DOCROOT/News/.htaccess as this will only be parsed for URIs /News/.... and hence out of any other URI path.

您将在htaccess文件中体验解析100s规则的性能,特别是如果匹配率现在很小。如果您当前的URI不以/ News开头,那么一个好方法是将所有这些重定向移动到DOCROOT / News / .htaccess,因为这只会针对URI / News / ....进行解析,因此不会出现任何其他URI URI路径。