I am writing a small web app mainly used just by myself so I'm not interested in fancy frameworks and page templating etc.
I need to be able to rewrite these urls:
/?page=parks
/?page=park&id=1
into
/parks
/park/1
Now, I have got very close with the following rules:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]*)$ /?page=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ /?page=$1&id=$2 [L]
and this works for most of the pages I have, but if I do the URL /settings it breaks. If I echo $_GET['page'] I get "inc". I have no idea why. Is this a PHP issue, or are my rules wrong?
You don't need RewriteCond %{REQUEST_FILENAME}\\.php -f
condition for this.
You can use:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ /?page=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ /?page=$1&id=$2 [L,QSA]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.