清洁和"脏"的网址

Tim*_* S. 2 php url .htaccess rewrite

我为PHP处理后的干净网址做了一个htaccess,但是对于我的搜索选项,我想要一个类似youtube的'?q = searchquery'.

RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^(.*)/$ index.php?d=$1 [L]
Run Code Online (Sandbox Code Playgroud)

这是我的htaccess,它适用于所有网址,但"http://www.website.com/search/?q=searchquery"却没有.现在我尝试了其他重写,比如这些

RewriteRule ^(.*)/\?(.*)/$ index.php?d=$1&$2

RewriteRule ^(.*)/\?q=(.*)/$ index.php?d=$1&q=$2
Run Code Online (Sandbox Code Playgroud)

他们不工作.

我还使用[R]标志查看了整个URI,并且没有显示问号中的所有内容.

RewriteRule ^(.*)/$ index.php?d=$1 [L]
Run Code Online (Sandbox Code Playgroud)

使用网址:http://www.website.com/search/? q = searchquery显示:http://www.website.com/search/

编辑:那么我该怎么做?\ O /

Nik*_*kiC 5

只需使用QSA(Query String Append)标志:

RewriteRule ^(.*)/$ index.php?d=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

如果使用查询字符串调用URL,则查询字符串将附加到生成的URL.

PS:您无法匹配重写规则中的查询字符串.在匹配规则之前,将剥离查询字符串.