问题
So the orginal url looked like
website.com/post.php?id=130
using the following htaccess rules i was able to remove .php from the url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
now the url looks like this
website.com/post?id=130
Now i wish to replace the "?id=" with a slash to make the url look like
website.com/post/130
any tips on what to do here ?
回答1:
You need an additional rule for that:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/proj1/$1.php -f
RewriteRule ^([\w-]+)/([\w-]+)/?$ $1.php?id=$2 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/proj1/$1.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
来源:https://stackoverflow.com/questions/41439512/php-url-replace-question-mark-and-parameter-with-slash