使用nginx屏蔽PHP GET url

使用nginx屏蔽PHP GET url,php,nginx,url-rewriting,Php,Nginx,Url Rewriting,我有一个使用php的网站。它是一个允许用户使用PHP GET调用搜索数据库的网站。然后,它将显示适合搜索的所有项目 有许多搜索过滤器(价格、来源网站、类别)。这是用户输入“blue car”和“dallas”搜索后url的样子 有没有办法让它看起来像: 不改变代码端的任何GET功能 我还让JQuery在站点上运行,如果可以用它来解决这个问题的话 注意:我使用的是nginx 编辑1 根据下面的建议,这似乎是一个nginx问题 这是我当前的/etc/nginx/sites available/d

我有一个使用php的网站。它是一个允许用户使用PHP GET调用搜索数据库的网站。然后,它将显示适合搜索的所有项目

有许多搜索过滤器(价格、来源网站、类别)。这是用户输入“blue car”和“dallas”搜索后url的样子

有没有办法让它看起来像:

不改变代码端的任何GET功能

我还让JQuery在站点上运行,如果可以用它来解决这个问题的话

注意:我使用的是nginx

编辑1

根据下面的建议,这似乎是一个nginx问题

这是我当前的/etc/nginx/sites available/default文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

}
当我简单地在最后一个'}'之前添加这个时:

# nginx configuration
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /array_search.php?path=$1 break;
}
}
这是nginx转换的apache代码,在下面的答案中,它似乎没有引起任何变化


我还放置了
列表(,$获取['search\u title'],$获取['search\u extra'],$获取['search\u location'])=explode('/',$获取['path']);//根据需要在顶部的索引和后搜索php文件中添加更多参数。

此答案假设您的Web服务器运行apache,并且启用了mod_重写模块(通常默认情况下启用)

这里有一个方法,我会接近这一点。但是,您必须在php文件的开头添加一些php代码(但不必更改现有实现中的任何其他内容)

在搜索.php
之后,首先在与
相同的位置创建或编辑
.htaccess
文件。将以下代码放入
.htaccess
文件中:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /after_search.php?path=$1 [NC,L,QSA]
这将使url被重写到幕后(这意味着人们仍然会看到)

然后在php文件中执行以下操作:

<?php
list(,$_GET['search_title'], $_GET['search_extra'], $_GET['search_location']) = explode('/',$_GET['path']); // Add more parameters as needed

谢谢你的回答,但我正在使用nginx。对不起,我打错了。您应该将显示array_search.php的部分更改为after_search.php。然后转到
http://example.com/s/blue+cars/l/Dallas
并查看它是否有效。告诉我您是否看到404错误消息,或者它是否在_search.php之后加载。另外,为了确保您的after_search.php应该位于站点的根目录下。
# nginx configuration
location / {
    if (!-e $request_filename){
        rewrite ^(.*)$ /after_search.php?path=$1 break;
    }
}