问题
I'm trying to rewrite the URL using htaccess, but I have some problems that I hope you could help me with.
This is the contents of my .htaccess file
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./index.php?page=projects&id=$1
The following rule works great, it converts this url:
peterboruplund.dk/?page=projects&id=projectname
to this
peterboruplund.dk/projectname
But the problem is that I also want to be able to only view a page. Like if I write this url:
peterboruplund.dk/?page=info
It should go to the page called "info", like this:
peterboruplund.dk/info
My problem is how can I achieve both things at the same time?
best, Peter
回答1:
You can have another rule for /info
:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^/]+)/?$ ?page=$1 [L,QSA,NC]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=projects&id=$1 [L,QSA]
来源:https://stackoverflow.com/questions/25238393/htaccess-rewriterule-index-phppage-projectsid-1