I want to redirect my naked domain to https with www like => https://www.example.com
I am using Ubuntu 16.04, apache, Let’s Encrypt.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Rewrite rules will help you with this. It’s very powerful utility, you do almost all URL manipulations with it.
We will added needed rules to Apache config. If you use default configuration, it’s stored in file called
000-default-le-ssl.conf. Open it with text editor:
By default, this is content of file:
You need to add following rules:
First rule -
RewriteEngine On, enables rewrite engine for you. Second one is condition, if it’s you are not accessing via
RewriteRulewill execute. Third one is rule, it rewrites your URL to correct one -
When you add it, your file will look like:
It requires you to have
rewritemodule enabled. To make sure, execute this:
To make this changes in effect - you’ll have to restart Apache:
This can be done via
.htaccessto, but as you have access to config files, you can use config files. :)
This is done for @ayan, now let’s go on @newbie part. =) This depends on your setup. If you followed How To Secure Nginx with Let’s Encrypt on Ubuntu 16.04, you have 2 server blocks. One to redirect, and one for HTTPS. In that case, you just need to add
return. Let’s assume you have redirect block like this one:
If you change
https://www.$server_name$request_uri;, you’ll get desired result. And block will look as this:
Hi @xMudrii @ayan, I too want to do this, but somehow, I can’t figure out the default 301 redirection to example.com.
So, I have setup the LetsEncrypt SSL and it’s working fine, but instead of redirecting to www.example.com, all the redirection is pointing on example.com. and I am unable to figure it out.
I added your code, but that creates the redirection loop.
Edit (Answer) : I did fixed it from Wordpress backend, but updating the www in site url and wordpress url.
Want to learn more? Join the DigitalOcean Community!
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Sign up now
Thanks… It’s works but when url www.example.com it not redirect “https://www.example.com” please tell me how i will do it.