在.htaccess中将ID重写为斜杠

问题描述 投票:1回答:2

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

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

这是我的.htaccess文件代码:

RewriteEngine on
RewriteRule ^script/([^/\.]+)/?$ script.php?id=$1 [L]
php .htaccess url hyperlink id
2个回答
0
投票
RewriteEngine on    
RewriteRule ^script/(.*)$    script.php?id=$1 [L]

0
投票

您需要重新排序规则,将特定的重写置于顶部。用以下内容替换您的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]
© www.soinside.com 2019 - 2024. All rights reserved.