php URL - replace question mark and parameter with

2019-07-21 00:16发布

So the orginal url looked like

website.com/post.php?id=130

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

now the url looks like this

 website.com/post?id=130

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 ?

1条回答
闹够了就滚
2楼-- · 2019-07-21 00:40

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]
查看更多
登录 后发表回答