当我想用htaccess重写url,如localhost/sample/12 htaccess正在寻找样本和12个目录名


when I want to rewrite url with htaccess like localhost/sample/12 htaccess is looking for sample and 12 directory names

我试图使用。htaccess重写url。

我想要这个url localhost/sample.php?

我使用了这个代码

RewriteEngine On
DirectoryIndex index.php
RewriteBase /
RewriteRule sample/([0-9]+)/?$ sample.php?x=$1 [L,QSA,NC]

但是当我进入url localhost/sample/12 web服务器寻找一个名为sample的目录和其中的子文件夹12。

有什么问题吗?

将您的重写规则更改为如下,它将工作。

RewriteCond %{QUERY_STRING} (^|&)x=12($|&)
RewriteRule ^sample'.php$ /sample/12?&%{QUERY_STRING}