dsfsdfsdfsdf6455 2016-01-15 14:38
浏览 114
已采纳

删除前导斜杠NGINX

I have a double slash in my URL (which is not ideal).

So my app is hit at //signup.

Error message:

Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET //signin""

Anyway to change it to just /signup?

I have tried the below in the first location block (which is the one catching the proxy).

Maybe something along the lines of the...

location /apps/phpauthentication/1 {      
        rewrite  ^\//(.*)/$  /$1 break;  
        try_files $uri /app_dev.php$is_args$args;
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /app_dev.php last;
        }
    }

Full config:

server {
    listen 80;
    server_name localhost;

    root /srv/http/web;
    index app_dev.php index.php index.html;  

    location /apps/phpauthentication/1 {
        rewrite ^\//(.*)/$ /$uri permanent;
        try_files $uri /app_dev.php$is_args$args;
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /app_dev.php last;
        }
    }

    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass app:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        fastcgi_param APP_ENV dev;
        include        fastcgi_params;
    }

    location ~ \.php$ {
       fastcgi_pass   app:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       fastcgi_param APP_ENV dev;
       include        fastcgi_params;
    }
}

Thanks :)

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-01-15 16:44
    关注

    I have had success with the URI changing on the backend while processing with the following.

         location /apps/phpauthentication/1 {
           rewrite ^(.*)//(.*)$ /$1/$2 permanent;  ##First matches double slash and rewrites
           try_files $uri /app_dev.php$is_args$args;  ##URI is now /apps/1/signup
           if (!-e $request_filename) {
               rewrite ^/(.*)$ /app_dev.php last; ## Matches all request that pass from above
           }
    

    Now the URL in the browser never changes but the backend server now appears to have a valid path.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题