首页 > 解决方案 > Nginx 重写总是重定向

问题描述

我正试图通过这种重写example.com/a/a23uy324example.com/index.php/render?id=a23uy324进行重写: location ~ ^/a { rewrite ^/a/(.*)$ https://example.com/index.php/render?id=$1 break; }但是任何规则,例如last,breakpermanent- 都不会产生任何影响。站点仍然重定向到 PHP 脚本。请指教。

这是完整的配置:

server {
    listen       80;
    server_name  example.com www.example.com;
    return      301 https://$server_name$request_uri;
}

server {
    listen              443 ssl;
    server_name         example.com www.example.com;
    ssl_certificate     /var/www/example.com/certificates/certificate.crt;
    ssl_certificate_key /var/www/example.com/certificates/private.key;

    root /var/www/example.com/public_html;
    index index.php index.html index.htm;

    #works
    location ~ ^/a {
         rewrite ^/a/(.*)$  https://example.com/index.php/render?id=$1 break;
    }

    location ~* ^/(assets|files|robots\.txt) { }

    location / {
        try_files $uri $uri/ /index.php?/$request_uri;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/run/php/php7.0-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/example.com/public_html$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }

    location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 7d;
    }
}

标签: codeigniternginxurl-rewriting

解决方案


推荐阅读