Score:0

Issue with Nginx Url Rewrite /Redirect

us flag

For new site config I tried NGINX rewriting for the blog plan and keep the paths the same, just redirect from 'www.' to 'blog.'.

and plan for RSpace API and CME have been configured and the ALB.

www.qwerty.com/video/  www.qwerty.com/v/

Blog

www.qwerty.com/blog/category/educator-blog/
blog.qwerty.com/educator/
www.qwerty.com/blog/category/researcher-blog/
blog.qwerty.com/researcher/
www.qwerty.com/blog/category/librarian-blog/
blog.qwerty.com/librarian/

RSpace API

www.qwerty.com/api/external/
review.qwerty.com/api/external/

CME

www.qwerty.com/etc/cme_confirm.php
review.qwerty.com/etc/cme_confirm.php

So I did try this for For the nginx

# Redirect

server {

    listen      80;

    access_log  off;

    error_log   off;

    server_name www.qwerty.com/blog/category/educator-blog/;

    return 301 $scheme://blog.qwerty.com/educator/$request_uri;

}

# Redirect

server {

    listen      80;

    access_log  off;

    error_log   off;

   server_name www.qwerty.com/blog/category/researcher-blog/;

    return 301 $scheme://blog.qwerty.com/researcher/$request_uri;

}
    
  # Redirect
    
    server {
    
        listen      80;
    
        access_log  off;
    
        error_log   off;
    
         server_name www.qwerty.com/blog/category/librarian-blog/;
    
        return 301 $scheme://blog.qwerty.com/librarian/$request_uri;
    
    }

but its unable to fulfil our request it seems to just spin, an URL (https://new-dev2.qwerty.com/video/49). Does the order of the rules matter?

I've implemented a temporary fix via the load balancer to have '/video/'

with 'www.qwerty.com' redirected to review.qwery.com/,
IF
Path is/video*
Host is www.qwerty.com
THEN
Redirect tohttps://review.qwerty.com:443/#{path}?#{query}
Status code:HTTP_302

which allows apache redirects to work. but i am looking for the parament fix for NGINX.

output

[root@ip-10-0-11-216 ~]# curl -I http://www.qwerty.com/blog/category/educator-blog/
HTTP/1.1 301 Moved Permanently
Server: awselb/2.0
Date: Mon, 10 Oct 2022 08:19:16 GMT
Content-Type: text/html
Content-Length: 134
Connection: keep-alive
Location: https://www.qwerty.com:443/blog/category/educator-blog/

What is the issue here , any help would be apricated.

Richard Smith avatar
jp flag
Those are not valid `server_name` directives. See [server names](http://nginx.org/en/docs/http/server_names.html) and [how Nginx processes a request](http://nginx.org/en/docs/http/request_processing.html).
santosh baruah avatar
us flag
Could you please describe it a little bit?
us flag
`server_name` contains the hostname part of URL, it must not include any other components of the URL.
santosh baruah avatar
us flag
I have tried this , but same fixed output : server { listen 80; listen [::]:80; server_name www.test.com; location /video { rewrite /video(.*)$ /v$1 redirect; } }
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.