Answer the question
In order to leave comments, you need to log in
How to beautifully write rewrite .php file so that it is executed before the location responsible for fcgi processing?
In the process of transferring .htaccess to the nginx config, I encountered a problem: You
need to rewrite from example.com/a.php to example.com/b.php
location / {
rewrite ^/a.php$ b.php;
}
location ~ \.php$ {
fastcgi_pass localhost: 9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
location /a.php {
rewrite ^/a.php$ b.php;
}
location ~ \.php$ {
fastcgi_pass localhost: 9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
Answer the question
In order to leave comments, you need to log in
The longest match takes precedence, then other rules come into play.
location /a.php {
return 301 http://example.com/b.php;
}
It's still possible like this
if ($request_uri = /a.php) {
rewrite ^ http://$host/b.php? permanent;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question