Home  >  Q&A  >  body text

apache - url address rewriting How to distinguish ‘? ’ question mark

Address: http://localhost/aaa/bbb-ccc=222

RewriteRule ^([a-z,\/,_,0-9]*)-(.*)$ index.php?routeee=$1&$2 [L]

When using '-' to distinguish the address URL, the data can be obtained, '-' is equivalent to a separator

Array ([routeee] => aaa/bbb [ccc] =>222 )

When '-' in the url address is replaced with '? ‘The data cannot be obtained when RewriteRule ^([a-z,\/,_,0-9]*)?(.*)$ index.php?routeee=$1&$2 [L] http://localhost/aaa/bbb?ccc=222

Array ([routeee] => index [_php] => )

RewriteRule ^([a-z,\/,_,0-9]*)?(.*)$ index.php?routeee=$1&$2 [L] How should this rule be written so that it can match normally and obtain the correct data.

\? Escape ‘? 'If there is a question mark, it will not match.

Greatful

But this can be used in nginx

rewrite ^/(.)?(.)$ /index.php?route=$1&$2 last;This rule is normal in nginx.

ringa_leeringa_lee2713 days ago485

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:06:10

    apache ignores querystring by default
    RewriteRule ^([a-z,/,_,0-9]*)$ index.php?route=$1& [L,QSA]

    That’s it. It’s so easy to add querystirng when forcibly executing it

    reply
    0
  • Cancelreply