301重定向/修改可以使用模式 [英] 301 Redirect/Rewrites with Patterns
问题描述
我知道使用正则表达式的力量,我可以减少我301的成几行。但是,我没有脑力吧。
I know using the power of regex, I can reduce my 301's into a few lines. However, I do not have the brain power for it.
基本上我们的链接,从去:
Basically our links went from:
http://www.site.com/collection/womens-active (这也可以?品牌=连接到年底123查询)
http://www.site.com/collection/womens-active (this can also have ?brand=123 queries attached to the end)
要:
http://www.site.com/collection/active
womens-是改变的一部分。
"womens-" is the changed part.
一个简单的301完美的作品,即使有疑问,但这个htaccess的约100行。
A simple 301 works perfectly, even with queries, but there is about 100 lines for this in htaccess.
使用正则表达式,我们可以减少到几行?
With Regex, can we reduce this to a few lines?
推荐答案
使用 RedirectMatch
来代替:
RedirectMatch 301 ^/collection/([^/-]+)-active/(.*)$ /collection/active/$2
假设由是改变的一部分,你的意思是有可能是什么地方说:女子 -
Assuming by the "is the changed part", you mean there could be anything where it says "womens-".
编辑:由于这是其他方式,只是换了正则表达式分组和女装 -
Since it's the other way around, just swap the regex grouping and the "womens-":
RedirectMatch 301 ^/collection/womens-([^/-]+)/(.*)$ /collection/$1/$2
这篇关于301重定向/修改可以使用模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!