Change .php URL with id into .html

淺唱寂寞╮ 提交于 2019-12-13 03:59:18

问题


Given the PHP URL course.php?id=10 I want it to redirect to course.html and I want to use the id=10 on this page. How can I do this?


回答1:


You can't cleanly rewrite the url and not include the variable somewhere. You'll need to do something like so:

RewriteRule ^([0-9]+)/([^.]+)\.html $2.php?id=$1 [L]

Which will work for http://example.com/10/course.html.




回答2:


Create a .htaccess file and add the following:

RewriteEngine On
RewriteRule ^([^.]+)\.html$ $1.php [L]

Upload this to the root of your files (most of the time it's /var/www/ or /home/user/public_html/.



来源:https://stackoverflow.com/questions/10413777/change-php-url-with-id-into-html

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