删除前导斜杠NGINX

时间:2016-01-15 14:38:21

标签: php regex nginx rewrite

我的网址中有一个双斜杠(这不太理想)。

所以我的应用程序被点击//signup

错误讯息:

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

无论如何要将其更改为/signup

我在第一个位置块(这是捕获代理的位置)中尝试了以下内容。

也许有些事情......

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;
        }
    }

完整配置:

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;
    }
}

谢谢:)

1 个答案:

答案 0 :(得分:1)

我在使用以下内容进行处理时,后端的URI发生了变化。

protected void btnChoose_Click(object sender, EventArgs e)
{
    API_DatabaseEntities1 db = new API_DatabaseEntities1();

    if (ddlCustomer.SelectedValue == "Marisol") {

        tbDescription.Text = (from c in db.Customers
                                where c.CustomerID == 4
                                select c.ProductDescription).ToString();
        tbFName.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.Fname).ToString();
        tbSocial.Text = (from c in db.Customers
                            where c.CustomerID == 4
                            select c.SSN).ToString();
        tbDOB.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.DOB).ToString();
        tbFName1.Text = (from c in db.Customers
                            where c.CustomerID == 4
                            select c.Fname).ToString();
        tbMName.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.Mname).ToString();
        tbLName.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.Lname).ToString();
        tbPrimaryPhone.Text = (from c in db.Customers
                                where c.CustomerID == 4
                                select c.PrimaryPhone).ToString();
        tbSecondaryPhone.Text = (from c in db.Customers
                                    where c.CustomerID == 4
                                    select c.SecondaryPhone).ToString();
        tbAdd1.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.Address).ToString();
        tbCity.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.City).ToString();
        tbZip.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.Zip).ToString();
        tbEmail.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.Email).ToString();
        tbMonLease.Text = (from c in db.Customers
                            where c.CustomerID == 4
                            select c.MortLeaseAmt).ToString();
        tbEmployer.Text = (from c in db.Customers
                            where c.CustomerID == 4
                            select c.Employer).ToString();
        tbPosition.Text = (from c in db.Customers
                            where c.CustomerID == 4
                            select c.Position).ToString();
        tbHireDate.Text = (from c in db.Customers
                            where c.CustomerID == 4
                            select c.Position).ToString();
        tbWorkPhone.Text = (from c in db.Customers
                            where c.CustomerID == 4
                            select c.WorkPhone).ToString();
        tbGross.Text = (from c in db.Customers
                        where c.CustomerID == 4
                        select c.GrossIncome).ToString();

    }

    Debug.WriteLine(tbGross.Text);
}

现在,浏览器中的URL永远不会更改,但后端服务器现在似乎具有有效路径。