nice url with apache and php

拜拜、爱过 提交于 2019-12-25 14:06:34

问题


I have urls like /story.php?id=31
I want to show it as /31.html How?


回答1:


You'll want to use Apache's mod_rewrite engine.

The rule you are looking for would look something like this:

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



回答2:


mod_rewrite is the answer. See e.g. this guide or this one.


/31.html -> /story.php?id=31 (rendering your links is another - and easier - issue)

RewriteEngine on
RewriteRule   ^/([0-9]+)\.html$ /story.php?id=$1 [L,QSA]



回答3:


Using apache and mod_rewrite, a possible sollution could be:

RewriteEngine On
RewriteRule ^([0-9]+)\.html /story.php?id=$1 [NC,QSA,L]


来源:https://stackoverflow.com/questions/3109272/nice-url-with-apache-and-php

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