在.htaccess中将ID重写为斜杠

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在.htaccess中将ID重写为斜杠相关的知识,希望对你有一定的参考价值。

有人可以帮我从www.website.com/script/?id=3重写网址ID到www.website.com/script/3/

这意味着要删除id =?id。

这是我的.htaccess文件代码:

RewriteEngine on
RewriteRule ^script/([^/.]+)/?$ script.php?id=$1 [L]
答案
RewriteEngine on    
RewriteRule ^script/(.*)$    script.php?id=$1 [L]
另一答案

您需要重新排序规则,将特定的重写置于顶部。用以下内容替换您的htaccess内容:

RewriteEngine on
#rewrite /script/foobar to /script.php?id=foobar
RewriteRule ^script/([^/.]+)/?$ script.php?id=$1 [L]
#remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ /$1.php [L]

以上是关于在.htaccess中将ID重写为斜杠的主要内容,如果未能解决你的问题,请参考以下文章