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
duplicate question as : https://stackoverflow.com/questions/74101316/long-url-diffrent-domain-redirect-nginx-issue
do these changes work for me :
server {
listen 80;
server_name www.test.com;
#old url
location /education/7/abc-science {
# Unique handler for the URL you want to redirect.
# new url
return 301 $scheme://www.test.com/education/7/abc-science;
}
}
or do I need to add $request_uri; inside the location block
do I need to use this way to redirect from my old URL to the new one?
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!