Score:1

nginx - 301 redirect wrong URLs used on extern website

uz flag

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;
}
Score:2
jp flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.