By techprame
Hey everyone, I recently have moved to HTTPS version from HTTP. But since then, I am into trouble and problem is not solved. So, my query is, How to redirect user to HTTPS version of site regardless whatever he types. For ex., Let me explain:-
example.com —>>> `https:// www.example.com/
www.example.com —>>> https:// www.example.com/
https:// example.com —>>> https:// www.example.com/
Moreover, If in future I make my mind to move site to https:// example.com instead of https:// www.example.com, then what will be the code for this? Let me give example for this too.
example.com —>>> https:// example.com/
www.example.com —>>> https:// example.com/
https:// www.example.com —>>> https:// example.com/
I have seen that if a user types https:// example.com and I want it to redirect to https:// www.example.com/ then browser give warning about its security before redirecting. Hence, asks for users confirmation. This is bad thing and can destroy site owner image. This should not happen. :D
Please suggest .htaccess code for both types separately. For info, using Apache Web Server. :D
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!
Here is working code…
RewriteEngine On
RewriteBase /
301 Redirect of http://primesoft.in OR https://primesoft.in to https://www.primesoft.in
RewriteCond %{HTTP_HOST} ^primesoft\.in [NC]
RewriteRule ^(.*)$ https://www.%{SERVER_NAME}/$1 [R=301,L]
301 Redirect of http://primesoft.in to https://www.primesoft.in
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://www.%{SERVER_NAME}/$1 [R=301,L]
This comment has been deleted
Thanks everyone for the quick response. I can now successfully redirect my website to HTTPS. Thanks, bye.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.