递归正防爆pression为mod-rewrite [英] Recursive Regular Expression for mod rewrite

查看:173
本文介绍了递归正防爆pression为mod-rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用mod_rewrite来recursivly修改我的网页网址,但我无法弄清楚重写规则针对这种情况:

I'm trying to use mod_rewrite to recursivly modify my web page urls, but am not able to figure out rewrite rule for this situation:

我想从模式改变我的网址

I want to change my URLs from pattern

http://mywebsite.com/token1-token2-token3-token4-categoryname

http://mywebsite.com/?cat=categoryname&search=token1+token2+token3+token4

挑战是,令牌的URL的数量可能会有所不同,所以我需要以某种方式处理令牌匹配和转换递归。任何想法如何才能实现这一目标?

Challenge is that the number of tokens in url may vary, so I need to somehow handle token matching and conversion recursively. Any ideas how can this be achieved?

推荐答案

尝试:

# Remove all of the - and replace with +
RewriteRule ^(.*)-(.*)$ /$1+$2 [L]

# only rewrite when there are no more -
RewriteCond %{REQUEST_URI} !\-
RewriteRule ^(.+)\+([^\+]+)$ /?cat=$2&search=$1 [QSA,L]

这篇关于递归正防爆pression为mod-rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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