Pergunta

I would like to reroute ALL requests through index.php with one variable and preserving $_GET. If $_GET exists, it's always after first slash. Anything after first slash that's not $_GET should be ignored. Something like this:

www.example.com/contact => www.example.com/index.php?page=contact
www.example.com/contact/ => www.example.com/index.php?page=contact
www.example.com/contact/?mod=add&id=4 => www.example.com/index.php?page=contact&mod=add&id=4
www.example.com/contact/ignore => www.example.com/index.php?page=contact

I'm not that good with .htaccess so I made just this (even thou I'm sure it's not really good)

RewriteRule ^([^/\.]+)$ index.php?page=$1 [QSA,NC,N]
RewriteRule ^([^/\.]+)/$ index.php?page=$1 [QSA,NC,N,L]

First part is working OK, but I don't know how to make "ignoring" part. If I try to open www.example.com/contact/ignore I get 404 Not Found.

Foi útil?

Solução

RewriteRule ^([^/\.]+)/.*$ index.php?page=$1 [QSA,NC,N,L]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top