【问题标题】:NGINX URL with argument rewrite to URL without argument带参数的 NGINX URL 重写为不带参数的 URL
【发布时间】:2015-10-17 17:38:33
【问题描述】:

我的服务器上有 NGINX 背景。我无法弄清楚为什么我的规则不起作用。

如何重定向或重写它,以便我可以打开具有相同内容的 URL,例如:

http://www.example.com/my_dir/value/

如果我有这个网址,例如:

http://www.example.com/my_dir/filename.php?parameter=value

我尝试了一些解决方案,但没有奏效:

Case #1:
location /my_dir/ {
  if ($args ~* "filename.php/?parameter=value1") {
      rewrite ^ http://www.example.com/my_dir/$arg_param1? last;
  }
}

Case #2:
rewrite ^/my_dir/(.*)$ /filename.php?parameter=$1 last;

Case #3:
location /my_dir {
    try_files $uri $uri/ my_dir/filename.php?$args;
}

Case #4:
location /my_dir/ {
    rewrite ^/my_dir/filename.php?parameter=(-+([a-zA-Z0-9_-]+))?\$ /filename.php?parameter=$1 last;
}

我是否必须配置我的 PHP 文件才能使其正常工作? 有什么想法吗?

谢谢!

【问题讨论】:

    标签: nginx rewrite


    【解决方案1】:

    试试这个:

    location / {
    
        rewrite ^/my_dir/filename.php?parameter=(.*)/$ /my_dir/$1/ permanent;
    }
    

    或者:

    location /my_dir {
    
        rewrite ^/filename.php?parameter=(.*)/$ /$1/ permanent;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多