开发者

Apache Rewrite Regex conditionally appending a substring to the replacement?

Hi :) There's no better way to explain this one than by example.

USUAL CASE

I use this rewrite rule:

RewriteRule ^(.+)(\?.+)?$ index.php?params=$1 [L]

To do something like:

# abc.com/home      =>      abc.com/index.php?params=home
开发者_运维技巧

However, this discards any preexisting GET parameters, so with:

http://localhost/ajax/workouts/getExerciseDetails?exerciseID=41

I get:

params=ajax/workouts/getExerciseDetails

When I need:

params=ajax/workouts/getExerciseDetails&exerciseID=41

SO... My question in English is: Is there a way to conditionally append any preexisting GET params (aka the string after the '?') to the replacement AND still satisfy my main use of this regex?

If this cannot be done in the same rewrite rule, perhaps by using an if/then/else?

Thanks!


Just set the QSA flag to get the original query automatically appended to the new:

RewriteRule ^(.+)$ index.php?params=$1 [L,QSA]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜