R
R
Roman Sopov2015-08-14 10:01:23
Nginx
Roman Sopov, 2015-08-14 10:01:23

Nginx rewrite, how to disable *.php return?

The essence of the problem: you need to redirect the URLs /v1/... to v1.php, /v2/... to v2.php, while trying to open /v1.php gives a 404 error.
Config:

location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}
location / {
    rewrite ^/v1/(.*)$ /v1.php last;
    rewrite ^/v2/(.*)$ /v2.php last;
    rewrite ^(/resources/.*)$ $1 break;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2015-08-14
@sopov

For example like this

location /v1/ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root/v1.php;
    include fastcgi_params;
}
location /v2/ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root/v2.php;
    include fastcgi_params;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question