简体   繁体   English

.htaccess重定向301不适用于所有链接

[英].htaccess redirect 301 doesn't work for all links

Recently I've been having weird issues with one of my htaccess files. 最近,我的htaccess文件之一出现了奇怪的问题。 Basically, I had to Redirect 404 pages to relevant subpage, and I checked few random ones and thought everything was working fine until I checked all of them and realised only about 60% of my rules did work. 基本上,我不得不将404页重定向到相关的子页面,并且我检查了一些随机的页面,并认为一切正常,直到我检查了所有页面并意识到只有大约60%的规则可以正常工作。

I was unable to find solution to my problem and I tried quite few approaches. 我无法找到解决问题的方法,因此尝试了很少的方法。

Here's list of Examples of the Redirect 301s that I'm using: 这是我使用的重定向301的示例列表:

Redirect 301 /products/sampleproduct http://www.mysite.co.uk/products/overhead-lifting-solutions
**Redirect 301 /products/sampleproduct/rail-system http://www.mysite.co.uk/products/overhead-lifting-solutions/rail-systems
**Redirect 301 /products/sampleproduct/floor-wall-mounted-cranes http://www.mysite.co.uk/products/overhead-lifting-solutions/jib-cranes
**Redirect 301 /products/sampleproduct/vacuum-lifter-easyhand-t http://www.mysite.co.uk/products/overhead-lifting-solutions/vacuum-lifters
Redirect 301 /products/sampleproduct/vacuum-lifter-easyhand-m http://www.mysite.co.uk/products/overhead-lifting-solutions/vacuum-lifters
**Redirect 301 /products/sampleproduct/vacuum-lifter-vacuhand-v http://www.mysite.co.uk/products/overhead-lifting-solutions/vacuum-lifters
**Redirect 301 /products/sampleproduct/end-effectors http://www.mysite.co.uk/products/overhead-lifting-solutions/end-effectors
Redirect 301 /products/sampleproduct/mechline http://www.mysite.co.uk/products/overhead-lifting-solutions/chain-hoists
**Redirect 301 /products/sampleproduct/mechchain http://www.mysite.co.uk/products/overhead-lifting-solutions/chain-hoists

Redirects that don't work were marked with **. 无效的重定向标有**。 I have over 160 Redirect where about ~60 do not work. 我有160多个重定向,其中约60个无效。

2nd Redirect rule is not working because first one is taking precedence. 第二个Redirect规则不起作用,因为第一个优先。 First rule is redirecting anything starting with /products/sampleproduct thus overriding /products/sampleproduct/rail-system all the time. 第一条规则是重定向以/products/sampleproduct从而/products/sampleproduct覆盖/products/sampleproduct/rail-system You can either reverse the order of rules or better use RedirectMatch with regex support like this using regex anchors: 您可以颠倒规则的顺序,或者更好地使用带有 regex锚的regex支持的RedirectMatch

RedirectMatch 301 ^/products/sampleproduct/?$ http://www.mysite.co.uk/products/overhead-lifting-solutions
RedirectMatch 301 ^/products/sampleproduct/rail-system/?$ http://www.mysite.co.uk/products/overhead-lifting-solutions/rail-systems

You need to make this fix for rest of your rules and make sure to clear the browser cache before testing these. 您需要针对其余规则进行此修复,并确保在测试这些规则之前清除浏览器缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM