Search code examples
phpregexapacheurl-rewritingcherokee

rewrite-rule to properly handle ?-sign


I'm having a annoying issue with rewrite-using cherokee web-server.

I want to convert:

http://example.com/mypage.phtml?cmd=print
=> to =>
http://example.com/index.php?page=mypage&cmd=print

The problem is that the ?-sign messes up the cmd;

$_GET : array('page'=>'mypage', '?cmd'=>'print')

Cherokee is configured with:

regexp: ^/(.*)\.phtml(.*)$
internal subst: /index.php?page=$1&$2

So my question: How to best "eat up" the question-mark if present.

Regards,

//teson


Solution

  • Try matching it explicitly before the capturing parentheses:

    regexp: ^/(.*)\.phtml\??(.*)$
    

    \? is a literal ?, and the following ? means "match 0 or 1 times".