且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP $ _GET变量是空的,由于URL重写

更新时间:2023-02-24 12:47:18

[QSA] 添加到您的结束重写规则。这追加旧的查询字符串的结果。

请参见文档以获取更多信息。

I have rewritten a URL with .htaccess so it looks prettier. But when I add a query string after this URL, the keys and values won't be observed!

Did anyone experienced this problem?

In my .htaccess file, I tried several things to fix the problem, but nothing worked.

RewriteEngine On
[some code]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ ?site=$1

I have tried this rewriting, to see if it works:

RewriteRule ^search?q=g ?site=search&q=g

But if I print_r($_GET) in PHP, I will just get Array ( [site] => search ) Try it on http://kwtsports.bplaced.de/search?q=g.

I have a search field that redirects to /search?q=blablaSearchQuery, but how I said, the $_GET['q'] is empty.

This also doesn't work:

RewriteRule ^search?q=([a-zA-Z0-9_-]+)/?$ ?site=search&q=$1

Does anyone know, why this happens?

Add [QSA] to the end of your RewriteRule. This appends the old query string to the result.

See the docs for more information.