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

2023-09-02 11:40:42 作者:嘦怹

我已经重写的.htaccess的URL,所以它看起来prettier。 但是,当我这个网址后添加查询字符串,键和值将不会被发现!

没有人也遇到过这个问题?

在我的.htaccess文件,我试过几件事情来解决这个问题,但是毫无效果。

  RewriteEngine叙述上
[约code]
重写规则^([A-ZA-Z0-9 _-] +)/?$?网站= $ 1
 

我已经试过这种重写,来看看它是否工作:

 重写规则^搜Q = G =网站搜索和放大器;] Q = G
 
怎么得到这个ajax得到的值 我在外面定义了一个变量,可是值没传进去,获取的都是空值

但是,如果我的print_r($ _ GET)在PHP中,我只是让阵列([现场] =>搜索) 尝试在 http://kwtsports.bplaced.de/search?q=g 。

我有一个重定向到/搜索Q = blablaSearchQuery,但我怎么说,在 $ _ GET ['Q'] 是空的。

这也不起作用:

 重写规则^搜Q =(A-ZA-Z0-9 _-] +)/ $网站=搜索和;???Q = $ 1
 

有谁知道,为什么会这样?

解决方案

[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.