문제

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.

도움이 되었습니까?

해결책

RewriteRule ^([^/\.]+)/.*$ index.php?page=$1 [QSA,NC,N,L]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top