How do I redirect https:// to https://www

#1

How can I redirect the https:// version to the version with www. in it? Thanks in advance!

#2

Are you self-hosted and/or have access to your web server configuration?
For nginx add this section to /sites-available/yoursite.conf
You will need a SSL certificate (letsencrypt…) for both the www.domain.com and domain.com, I think they issue wildcard certs nowadays

server {
        listen 443;
        server_name yoursite.com;
        # $scheme will get the http protocol
        # and 301 is best practice for tablet, phone, desktop and seo
        return 301 $scheme://www.yoursite.com$request_uri;
}

You can also do this in javascript on the page if you can edit default.hbs - not elegant and more of a hack but it works, put this first thing after <body> tag

    <script>
        if(window.location.host == 'yoursite.com')
    {
            window.location.href="https://www.yoursite.com" + window.location.pathname;
    }
    </script>
#3

If you use cloudflare, you can do this via a page rule without touching your server or website.

BTW, everyone removes www from their URLs nowadays. It is unnecessary and user has to press another 4 additional keystrokes for nothing.

#4

Thanks for this! I did the hack but I have no idea where to add the section. I cannot find the sites-available map.

closed #5

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