Preety url with htaccess

只谈情不闲聊 提交于 2021-02-10 18:19:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!