1

mod_rewriteを使用してWebページのURLを再帰的に変更しようとしていますが、この状況での書き換えルールを理解できません。

URLをパターンから変更したい

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

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

課題は、URL内のトークンの数が異なる可能性があるため、トークンのマッチングと変換を再帰的に処理する必要があることです。これをどのように達成できるかについてのアイデアはありますか?

4

2 に答える 2

1

試す:

# 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]
于 2012-07-02T03:13:29.577 に答える
0

RewriteRule ^/?(.+)\-([^\-]+)$ /?cat=$2&search=$1 [QSA,L]

于 2012-06-30T15:09:15.360 に答える