递归正防爆pression为mod-rewrite递归、pression、rewrite、mod

2023-09-02 00:58:46 作者:谁旳坚持 释放了谁的伤゜

我试图使用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]