Welcome! Log In Create A New Profile

Advanced

Redirects and SSL troubles

Posted by rwslippey 
Redirects and SSL troubles
May 05, 2019 04:49PM
Good afternoon all,

I'm having a bit of trouble working out some redirects and stuff in my config. The file in question is for a redirect from my old domain to the new one. There has been some structure change and ssl added.

So what I'm trying to do here is, http of old domain to https of new domain for the root domain www and non-www

and then some specific redirects for specific pages.

The problem is my config either doesn't redirect http://oldomain.com/something at all or it redirect back to just the main page of the new domain.

I'm sure my config has some issues. I'm using lets encrypt and cert-bot for SSL so I think I goofed something up here


I may have went a little crazy with my "removed for security" but I wanted to be safer than sorry.

server {

server_name www.olddomain.com olddomain.com;
# redirects both www and non-www to https
return 301 https://newdomain.com;
if ( $redirect_uri ) {
return 301 https://newdomain.com/$redirect_uri;
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate REMOVED FOR SECURITY
ssl_certificate_key REMOVED FOR SECURITY
include REMOVED FOR SECURITY # managed by Certbot
ssl_dhparam REMOVED FOR SECURITY # managed by Certbot


}
map_hash_max_size 262144;
map_hash_bucket_size 262144;

map $request_uri $redirect_uri {
/ /;
/about-us-1 /about-us;
/book-now /contact;
/blog /blog;
/blog/... /blog;
/blog/page.. /blog;
/contactus /contact;
}
server {
if ($host = www.olddomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = olddomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
listen [::]:80;

server_name www.olddomain.com olddomain.com;
return 404; # managed by Certbot

}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 204
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready