addis_a
February 14, 2015, 10:58pm
1
Hello,
I need to redirect some URLs after redesigning my website.
I use a 301 redirect for HTTP to HTTPS protocole :
if ($scheme = “http”) {
return 301 https://$server_name$request_uri;
}
But how do I redirect URLs that have been changed ?
ie. mywebsite.com is available for purchase - Sedo.com to
mywebsite.com is available for purchase - Sedo.com
I did try
if ( $request_filename ~ oldname.html/ ) {
rewrite ^ mywebsite.com is available for purchase - Sedo.com ? permanent;
}
But this doesn’t work.
My website is hosted on a server with Direct Admin runing on a CentOS
with
Nginx as webserver. Don’t know if it helps.
Thanks in advance for help
On Sat, Feb 14, 2015 at 10:57:26PM +0100, JACK LINKERS wrote:
But how do I redirect URLs that have been changed ?
ie. https://mywebsite.com/oldname.html to https://mywebsite.com/newname.html
location = /oldname.html { return 301 /newname.html; }
I did try
if ( $request_filename ~ oldname.html/ ) {
rewrite ^ https://mywebsite.com/newname.html/ ? permanent;
}
But this doesn’t work.
Yes, it does. If your incoming request matches the string
“oldname.html/”.
It just isn’t a very good way of implementing it.
f
Francis D. [email protected]
Hi Francis,
Thanks for your input. What would be the best ways doing it then ?
(I forgot to mention there is a large amount of URLs : +/- 20)
Is this a good way ? :
map $old $new {
oldlink.html newlink.com
oldink2.html newlink2.html
}
location $old {
return 301 $scheme://$host$new;
}
If not, could you show me an example ?
Thanks in advance
2015-02-14 23:22 GMT+01:00 Francis D. [email protected] :
On 14/02/2015 21:57, JACK LINKERS wrote:
ie. https://mywebsite.com/oldname.html to
My website is hosted on a server with Direct Admin runing on a CentOS
with Nginx as webserver. Don’t know if it helps.
Thanks in advance for help
Hi Jack,
I’m no nginx expert, but I think you should use location instead of if,
its faster and less prone to create other errors.
I think you can also use 301 redirects.
I would proceed to set up lots of location clauses thus:
location = /oldurl$ {
return 301 https://$server_name/newurl;
}
Hope this works for you
Ian
On Sat, Feb 14, 2015 at 11:30:19PM +0100, JACK LINKERS wrote:
Hi there,
Thanks for your input. What would be the best ways doing it then ?
(I forgot to mention there is a large amount of URLs : +/- 20)
A bunch of lines like
location = /oldname.html { return 301 /newname.html; }
(It’s the “if” that isn’t the good way of implementing it.)
Is this a good way ? :
No.
I’d say just use “location =”.
Good luck with it,
f
Francis D. [email protected]
Ok, thanks !
2015-02-14 23:37 GMT+01:00 Francis D. [email protected] :