我试图使用。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}