php URL-用斜杠替换问号和参数 [英] php URL - replace question mark and parameter with slash
本文介绍了php URL-用斜杠替换问号和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此原始网址看起来是
website.com/post.php?id=130
使用以下htaccess规则,我可以从网址中删除.php
using the following htaccess rules i was able to remove .php from the url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
现在网址看起来像这样
website.com/post?id=130
现在,我希望用斜杠替换?id =,以使网址看起来像是
Now i wish to replace the "?id=" with a slash to make the url look like
website.com/post/130
在这里做什么的任何提示?
any tips on what to do here ?
推荐答案
为此您需要一个附加规则:
You need an additional rule for that:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/proj1/$1.php -f
RewriteRule ^([\w-]+)/([\w-]+)/?$ $1.php?id=$2 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/proj1/$1.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
这篇关于php URL-用斜杠替换问号和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文