【发布时间】:2015-07-23 13:13:45
【问题描述】:
我的目标:将 URL 从 host.com/?abc 重写为 host.com/abc 并能够通过 $_SERVER['QUERY_STRING'] 请求它。我发现了以下规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?$1 [L,QSA]
但无论出于何种原因,我的 $_SERVER['QUERY_STRING'] 都是空的,除非我输入 '?'在查询字符串前面。当我执行 print_r( $_SERVER ) 或 print_r( $_GET ) 时,我的查询字符串不存在于任何地方。有什么建议我做错了吗?谢谢!
更新; 我使用 nginx 作为“前端”代理,并使用以下规则将请求重定向到 apache:
server
{
listen 80;
root /var/hosts/hostcom;
index index.php index.html index.htm;
server_name host.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8010;
}
location ~ /\.ht {
deny all;
}
}
如果我直接请求apache端口,它可以工作host.com:8010/?abc,但不能通过nginx,有什么建议吗?谢谢!
【问题讨论】:
-
这取决于路线,但
host.com/abc应该把“abc”放在$_GET... -
@Random 这就是问题所在,你知道为什么没有吗?
标签: php apache mod-rewrite nginx