【问题标题】:nginx PHP slash before each GET parameter每个 GET 参数前的 nginx PHP 斜杠
【发布时间】:2016-06-22 02:05:30
【问题描述】:

当我执行print_r($_GET) 时,参数前会出现一个斜杠。

Array ( [video_name] => /onajr ) 1

nginx 配置 try_files $uri $uri/ /index.php?video_name=$uri;

为什么会这样,我该如何删除它?

【问题讨论】:

    标签: php nginx url-rewriting


    【解决方案1】:

    所有nginx URI 都以斜杠开头。如果您确实必须提取没有前导斜杠的 URI,那么这样的方法可能对您有用:

    location / {
        try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
        rewrite ^/(.*)$ /index.php?video_name=$1 last;
    }
    

    详情请参阅thisthis

    【讨论】:

    • 重写或尝试文件哪个更快?
    • 如果您可以在 PHP 中使用前导斜杠,您的原始配置会更高效。
    猜你喜欢
    • 1970-01-01
    • 2016-04-21
    • 2016-06-16
    • 1970-01-01
    • 2014-11-22
    • 2014-09-22
    • 1970-01-01
    • 2015-06-29
    • 2015-01-27
    相关资源
    最近更新 更多