Answer the question
In order to leave comments, you need to log in
Correct redirect with URL change?
Hello! I don't know the answer to my question.
I want to make sure that when the user enters any link in the address bar of the site, he is always returned to site.ru/ , example: the user opened the site as site.ru/test/33 he was redirected to site.ru/ . But at the same time, so that $_GET and other resources of the site would be available, tell me, please =)
Answer the question
In order to leave comments, you need to log in
I thought I could do with a simple rewrite, but it was not so, it turned out to be a little more complicated.
Only access to the index file is allowed, in the example it is index.php, it should contain all the logic of the site. If you need access to other php files, fix location = /index.php
it to something like location ~ /\.php
. Everything else is prohibited.
server {
listen 80;
server_name site.ru;
root /var/www;
index index.php;
# Если путь существует
location = / { }
location = /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
location / {
deny all;
return 302 /;
}
# Если путь не существует
error_page 404 = @notfound;
location @notfound {
return 302 /;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question