问题
I have url localhost/product/q.php?id=1&product=my-product
how to make the url into localhost/product/1/my-product
using .htaccess
回答1:
You use a RewriteRule
which consists of a regex to apply to the pretty URL accessed by the user and a replacement which will then be used by the server/scripts.
RewriteRule ^product/(\d+)/(.*)$ /product/q.php?id=$1&product=$2 [L]
RewriteRule : Type of action
^product/(\d+)/(.*)$ : Regex to run against URL
/product/q.php?id=$1&product=$2 : Replacement URL
[L] : Flags; L == Last
Note
Having re-read the question you may need to add:
Options -MultiViews
To the top of your .htaccess
file as well.
来源:https://stackoverflow.com/questions/65424077/preety-url-with-htaccess