Categories: eLearning

Force redirect to HTTPS using .htaccess file in PHP

Before starting anything, Let’s have a look on Introduction of .htaccess

If you have SSL installed on your domain, but how to force redirect your website to HTTPS as opposed to the non-SSL version i.e. HTTP? Today, TechnoGripper India will demonstrate to you proper guidelines to force redirect https using the .htaccess file on the root folder to guarantee that your website always redirected to  HTTPS.

Code to force redirect to HTTPS using .htaccess file:

All web traffic can be forced redirect to HTTPS by inserting the mentioned code into the .htaccess file on your website root folder. These lines should be included on the top of the file over any other code with a similar starting prefix:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]



How to add force HTTPS Code in the .htaccess file:

Follow these steps to add force HTTPS Code in the .htaccess file:

Step 1: Login into Web Hosting Cpanel with your username & password.

Step 2: Find “File Manager” and click on it.

Step 3: Find public_html directory. And then search for the .htaccess file in the public_html directory itself.

Step 4: If .htaccess file is not there. Create a new file with the name .htaccess & embedded the above code in the .htaccess file.

It’s done. That’s all.

Thanks for your valuable time. Stay tuned with TechnoGripper India at WEXT.in Community for more Interesting & Informative Articles.

Don’t hesitate to ask any question related to Core PHP, WordPress, Opencart, HTACCESS, HTML 5, Bootstrap, Angular JS, Ajax, J-Query. We are as TechnoGripper India here to help you.

View Comments

  • It's really a nice and useful piece of info.
    I'm glad that you simply shared this useful information with us.
    Please keep us informed like this. Thanks for sharing.

Recent Posts

Mistakes of Entrepreneurs: Deadly Mistakes of Entrepreneurs

The mistakes of entrepreneurs can be one of the costliest mistakes. Not only it can cost your business, but it…

5 days ago

Top Young Entrepreneurs from India, you must know about

Today, We'll featuring top young entrepreneurs from India, who have actually inspired entrepreneurs across the world. India has one of…

1 week ago

नए उद्यम विकास को प्रभावित करने वाले कारक।

भारत में उद्यमिता विकास  को प्राभावित करने वाले कारण निम्न हैं। जैसे : -  आर्थिक, सामाजिक और सांस्कृतिक , मनोवैज्ञानिक,…

1 month ago

उद्यमियों (एंटरप्रेन्योर) के लिए कौन सी योजना उपलबध है

भारत सरकार ने हमेशा से ही उद्योग के क्षेत्र को बढ़ावा देने की कोशिश की है. देश में उद्यमियों की…

2 months ago

उद्यमियों ( एंटरप्रेन्योर ) के लिए वैश्विक समस्या क्या है

किसी भी देश में आर्थिक विकास की गति को बढ़ावा देने तथा व्यावसायिक समस्याओं का समाधान करने में उद्यमी की…

2 months ago

Cocofit Has Raised INR 5 Crores From Shark Tank India

The shark tank India startup Cocofit has raised an unconventional amount of 5 rupees for the equity of 5% from…

2 months ago

REACH US

WEXT India Ventures

C-22, Sector 65, Noida, Uttar Pradesh – 201301

Corporate Queries:

Email: ping@wext.in
Mobile: +91 956 085 0036

Advertisement Queries:

Email: advertise@wext.in
Mobile: 956 085 0036