Redirect http url to https

Force redirect http to https using htaccess

Force redirect http traffic to https

Redirect http to https url using simple file. If you have recently switched to https version, which is recommended, then you want to force the traffic to https.

This can be accomplished using .htaccess file.

How to redirect https to http

1. Create/update the .htaccess file on your root website.
2. Add the following line on the top part of the .htaccess file


RewriteEngine On

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

3. That is it. You don’t need to restart the server for this case.

You can refer this page for more htaccess examples

Redirect to home page on 404 – htaccess

How to redirect to home page on page not found 404

If you have a page that is not found, then google and others will penalize your site for not finding the page. Hence, you should handle that internally.

At least the easiest thing one can do is to redirect the site to the home page using .htaccess directives.

Homepage redirection 404

First create a .htaccess file if you don’t have one yet. Place this .htaccess file in the root of the website.

Then add the following line in the .htaccess file.


Options -MultiViews
RewriteBase /
RewriteEngine On
#if you have other redirect rules, have them here
#put this at the end of the file.
ErrorDocument 404 /

Mind you, the page you are going to redirect to should be relative path.
On the above file, those starting with # are comments and won’t be read by the server.

Hope it helps. Let me know if this helps you or if you have better method by leaving the comment down.