首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否在搜索查询上重写Nignx模式?

是否在搜索查询上重写Nignx模式?
EN

Stack Overflow用户
提问于 2015-08-05 15:32:53
回答 1查看 706关注 0票数 0

这是我需要做的一件非常基本的事情,但我想不出这件事。

我的nginx.conf中有以下规则

代码语言:javascript
复制
    location ^/search {
        #try_files index.php?search=$1  last;
        rewrite ^/search/(.*)/ index.php?search=$1;
        #rewrite ^/search/([^/]+)/page/([^/]+)/?$ /index.php?search=$1&page=$2;
    }

    location ^/article {
        rewrite ^/article/([^/]+)/([^/]+)/$ /index.php?layout=article&id=$1;
    }

    location ^/images {
        rewrite ^/images/([^/]+)$ /images/$1 break;
        rewrite ^/images/([^/]+)/([^/]+)$ /images/$1/$2 break;
    }

    location ^/css {
        rewrite ^/css/([^/]+)$ /css/$1 break;
        rewrite ^/css/([^/]+)/([^/]+)$ /css/$1/$2 break;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
    }

基本上我想做的就是将下面的查询匹配到上面的搜索结果。

代码语言:javascript
复制
example.com/search-term1/
or
example.com/search term/
or 
example.com/search/search-term1/
or
example.com/search/search-term1/page/1/

上面的url模式?我该怎么做?上面的规则给出了错误500内部服务器错误。

在Nginx日志中,我得到如下内容

代码语言:javascript
复制
2015/08/05 12:56:39 [error] 11136#0: *2 could not find named location "@rewrite", client: 202.172.107.194, server: example.com, request: "GET /search/search-term1/page/1/ HTTP/1.1", host: "example.com"
EN

回答 1

Stack Overflow用户

发布于 2015-08-06 13:06:49

我通过将它们移出位置块并将它们直接放入服务器块修复了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31826121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档