htaccess to rewrite url


htaccess to rewrite url

所以我听说你可以使用htaccess重写网站url。例如,我有一个php页面来查看线程/帖子,它看起来像这样:

http://website.com/view.php?id=133

有人告诉我,我可以让它看起来像

http://website.com/view/133

我也有这个链接

http://website.com/delete.php?id=144

我希望它看起来像这个

http://website.com/delete/144

我该怎么做?

谢谢。

RewriteRule ([a-z])/([0-9])' $1.php?id=$2

([a-z])将替换您的页面名称([0-9])将分别替换右侧中的id

请参考

http://corz.org/serv/tricks/htaccess2.php

是的,您可以使用.htaccess.完成所有这些操作

查看我的答案在WAMP 中将localhost/xxx重定向到localhost/xxxx.php

我希望它能有所帮助。

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

您必须将url作为http://website.com/delete/144,则它将被重定向到delete.php,144作为id。

例如,

<a href="http://website.com/delete/$id">Delete</a>