【问题标题】:Making nginx change parameter in url使 nginx 在 url 中更改参数
【发布时间】:2016-03-31 07:03:37
【问题描述】:

如何更改 url 中的参数
例如 https://example.com/r.php?12345https://example.com/12345

nginx 配置文件:

server {
    listen       80;
    server_name  example.com;
    rewrite_log on;
    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/example.com;
    index index.php index.html index.htm;
    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_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    } 
}

以及在哪里添加块 在conf文件里面?

【问题讨论】:

    标签: mod-rewrite nginx


    【解决方案1】:

    如果 URI 未映射到本地文件,try_files 的最后一个元素是默认操作。因此,用所需的重写替换您的 404 错误。试试:

    location / {
        try_files $uri $uri/ /r.php?$uri;
    }
    

    详情请见this document

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 2014-07-22
      相关资源
      最近更新 更多