Score:0

nginx: [warn] server name has suspicious symbols with long domain redirect

br flag

What is the best way in Nginx to redirect two Long domains URLS, I would like to configure a redirect between two domains like this:

I'm sure this has been asked before, but I can't find a solution that works.

original link:

https://qwerty.test.com/education/7/abc-science

New link

https://www.test.com/education/7/abc-science

I have tried this :

server {
    listen 80;
    listen 443 ssl;
    server_name qwerty.test.com/education/7/abc-scienc;
    return 301 $scheme://www.test.com/education/7/abc-science$request_uri;
}

Still receive some errors

nginx: [warn] server name "education/7/abc-scienc
" has suspicious symbols in /etc/nginx/conf.d/redirect.conf:9

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

do I need to use this way to redirect form my old URL to new ?

location = /content/unique-page-name {
  return 301 /new-name/unique-page-name;
}

Can anyone help me with this ? What is wrong here ?

Any help is appreciated! thanks!

Score:0
ru flag

Server name should ONLY be your domain, not your full URL.

Which means your server_name should be qwerty.test.com.

You then should use location blocks for proper redirects, like so:

server {
    listen 80;
    listen 443 ssl;
    # Configure your SSL too!
    
    server_name query.test.com;

    location /education/7/abc-science {
        # Unique handler for the URL you want to redirect.
        return 301 $scheme://www.test.com/education/7/abc-science;
    }

    location / {
        # Ideally you need a site level redirect for *any* URI 
        # so that the request is sent to the different site 
        # on any other request URI.
        return 301 $scheme://www.test.com$request_uri;

        # Alternatively, do a different site configuration here for 
        # any other pages that don't redirect.
    }
}
Santosh Baruah avatar
br flag
ok , Could you give share some idea , what should be do with two different URL redirect as example i have : SE Engineering Series https://www.test.com/education/eng 
 new https://www.test.com/education/engineering or https://www.test.com/research/journal/immunology-infection 
 new https://www.test.com/research/immunology-and-infection
Santosh Baruah avatar
br flag
Is this like :: location /research/journal/immunology-infection { # Unique handler for the URL you want to redirect. return 301 $scheme://www.test.com/research/immunology-and-infection; }
Santosh Baruah avatar
br flag
the curl output curl -I test.com/research/journal/immunology-infection HTTP/1.1 301 Moved Permanently Server: awselb/2.0 Date: Wed, 19 Oct 2022 19:38:52 GMT Content-Type: text/html Content-Length: 134 Connection: keep-alive Location: https://test.com:443/research/journal/immunology-infection
Santosh Baruah avatar
br flag
do I need to add $request_uri in the location block?
ru flag
@SantoshBaruah not if you're doing a direct location/url redirect. You need $request_uri if you're doing a full site redirection from a.site.com to b.site.com at the same request URI.
I sit in a Tesla and translated this thread with Ai:

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.