Redirect www.domain.com to domain.com with script


#1

How to set redirect for www.domain.com to domain.com

Is it possible to redirect all the requests including www to without www using certbot?

Im using the script “certbot --nginx” for installing SSL.

Requirement in short:

http://test.com > https://test.com
http://www.test.com > https://test.com
https://www.test.com > https://test.com

Thank you,


#2

Hi @pranav,

AFAIK, no, certbot can redirect http://test.com to https://test.com and http://www.test.com to https://www.test.com but is not what you want to do so, you should create the redirections by hand.

Cheers,
sahsanu


#3

@sahsanu: Thanks for the update.
Is the script used by “certbot --nginx” available so that I can tweak as per my requirement in my machine?


#4

Hi @pranav,

You can use this as an example:

server {
    listen 80;
    server_name domain.tld www.domain.tld;
    return 301 https://domain.tld$request_uri;
}

server {
    listen 443 ssl;
    server_name www.domain.tld;
    ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
    #other ssl options
    return 301 https://domain.tld$request_uri;
}

server {
    listen 443 ssl;
    server_name domain.tld;
    #your root, index, etc. stuff
    ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
    #other ssl options
}

Cheers,
sahsanu


#5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.