How to achieve automatic transfer from http to https

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zhong87916
Forum Newbie
Posts: 1
Joined: Tue Mar 06, 2018 4:39 am

How to achieve automatic transfer from http to https

Post by Zhong87916 »

Hello, everyone. Very lucky to be here, I would like to ask a question.

I want to install an SSL certificate on my website. Hopefully, after the installation, every web page in the website can be browsed in this way: If I visit http: // URl, it will automatically jump to https: // URl.

I do not know which company's SSL is better. If you can help recommend one, I will be very grateful.


Another question:

In the server's root directory of my website, I have stored a file.htaccess.

content:
-----------------------------------------------

RewriteEngine On

RewriteCond% {SERVER_PORT} 80

RewriteRule ^(.*)$ https://www.weldedmeshfence.com/$1 [R,L]
-------------------------------------------------- ------------------------------------------------

I found it won't work. Can anyone here help me correct it.

My website is http://www.weldedmeshfence.com.

Thank you very much.
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: How to achieve automatic transfer from http to https

Post by thinsoldier »

It seems your SSL isn't set up correctly.

Once it is set up correctly, if your .htaccess file isn't working, make sure you vhost definition allows .htaccess files to operate.
Warning: I have no idea what I'm talking about.
protopatterns
Forum Newbie
Posts: 9
Joined: Sun Jan 28, 2018 11:18 am

Re: How to achieve automatic transfer from http to https

Post by protopatterns »

Zhong87916 wrote:after the installation, every web page in the website can be browsed in this way: If I visit http: // URl, it will automatically jump to https: // URl.
Hi Zhong87916,

After you get your SSL resolved correctly, try this:

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If your server has the rewrite engine installed (almost all servers do), this makes all of your 'http://' rewrite to 'https://', without redirecting to your homepage.
Post Reply