Answer the question
In order to leave comments, you need to log in
Redirect in Nginx any requests and links to the site to the main page?
UPDATE: I forgot to add that location / happens to proxy_pass on apache, so the solution below will most likely not take off.
Good afternoon, please tell me, there is a site example.com. It is
necessary that any requests to it be redirected to the main page of the site, and no matter what type of request:
example.com/blabla.php , example.com/blabla.html , example. com/blabla.pdf ,
example.com/blabla and so on.
Standard php, html, htm links can be redirected by extension (or by universal mask "any name - dot - any extension"):
location ~* \.(html|htm|php)$ {
return 301 http://example.com ;
}
But what to do with links like example.com/blabla
Thanks in advance for your help.
Answer the question
In order to leave comments, you need to log in
location = / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 180;
}
location / {
rewrite ^ / permanent;
}
That's how it all worked, thanks! )
Here's another option:
location ~* (?<=\/).* {
return 301 /;
}
location = / {
proxy_pass http://127.0.0.1:8887/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header HTTPS YES;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 180;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question