For some reason, some extern websites have links to my website subdomain.example.com looking something like this: <a href="https://subdomain.example.com/https://subdomain.example.com/index.php?id=54597">Link</a>
I cannot get these links corrected as I have no control over these links. So instead of showing a 404 error, I would like to redirect https://subdomain.example.com/https://subdomain.example.com/index.php?id=54597
to https://subdomain.example.com/index.php?id=54597
via nginx but I cannot get a location to match, once it includes a colon. Is there a way to get this to work?
something like
location ~ "^https://subdomain.example.com/index.php$" {
return 301 /index.php?$query_string;
}
All URIs in Nginx begin with a leading
/
and are normalised to remove consecutive//
s.You should change your regular expression to:
^/https:/subdomain\.example\.com/index\.php$
and place it above thelocation
block which matches URIs ending with.php
.Alternatively, use an
=
operator to exactly match a single URI, for example:See this document for details.