1

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;
}

1 Answer 1

2

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 the location block which matches URIs ending with .php.

Alternatively, use an = operator to exactly match a single URI, for example:

location = /https:/subdomain.example.com/index.php {
    return 301 /index.php$is_args$args;
}

See this document for details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .