Monday, April 15

How to redirect http to https in wordpress using htaccess

Today I faced a very simple issue and I am going to share that with all of you. In general when we move our wordpress site from Http to Https then we simple change urls in WordPress->Settings->General.

But still if any user is going to open your site with http then it will show in http and that’s very bad for you site ranking. For an example my site is on SSL and url is as below:

Now when you will try to open below urls then you won’t redirect on https automatically

If https:// is not in the prefix, the HTTP link loads instead. To overcome this issue you just need to add the following into your .htaccess in between the tag:

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

If there were no additional modifications done to your .htaccess, it should look like the following:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Rewrite HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

# END WordPress

Let me know if you have any issue in above so I will help you.

0 0 votes
Article Rating
Notify of

Newest Most Voted
Inline Feedbacks
View all comments
5 years ago

Nice article with point to point information…It reduced some of my time.

Would love your thoughts, please comment.x