ASPNetFAQ.com: What is ASP.NET?

Technology posts on ASP.NET, IIS, Windows (+ a little Linux), Cloud Servers, Hosting, and more!
  • Blog Home
Search the site...

Redirect from HTTPS to HTTP using an htaccess file

Tweet
Share
0 Shares

I ran into some issues recently where I needed to redirect HTTP to HTTPS for all requests on my site. It took a surprising amount of Google searching and tinkering to find a solution. Ultimately the solution was pretty simple, so I figured I’d share it here and hopefully same other people some time.

So, backstory, I enabled SSL on one of the sites I run but when testing I noticed a few things needed to be fixed for the site to work 100% perfectly under HTTPS. I reached out to the web host and requested for the SSL (port 443) to be turned off for now until I could fix the issues. This request may as well have been asking for a trip to the moon.

Looking for the BEST WordPress Hosting?
Read my review of the Best WordPress Hosting or click the banner below to check out SiteGround's plans - starting under $4/month!
Do you already have a site? They'll migrate it for you - FREE!

Web Hosting

The tech (three of them at different times actually) didn’t know how to do this. So I would up removing the SSL certificate via their control panel and figured that might do the trick. No, it didn’t. So I had them cancel the SSL “service” for me, hoping the system would be smart enough to turn off port 443 after it was canceled. No, it wasn’t.

So I went in search for a solution on my own. For about 20 years I ran all my sites on Windows – which is still an awesome solution – but currently my sites (running WordPress) are running on Linux – nginx specifically. Knowing this, I started looking for a solution using the htaccess file (similar to a .config file on Microsoft platforms). Even though I’m horrible at RegEx, I knew that redirecting from this file was an option. I just didn’t know how to check for SSL and what the rule should look like to do what I wanted.

Anyway… cutting to the chase… here are the lines I added to the htaccess file that redirected *all* HTTPS requests that my site received over to HTTP. It performs a 301 redirect to help with search engine tracking (passing “the juice” to the destination URL).

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

Boom! Yep, it really was that simple. The first line checks to see if the request is via SSL and the second line redirects to the exact same URL except over a non-secure (HTTP) channel.

I hope that saves other people some time!

 

More from my site

  • What makes good web hosting?What makes good web hosting?
  • How to use telnet to test ssl/https websitesHow to use telnet to test ssl/https websites
  • Cloud Server Performance MetricsCloud Server Performance Metrics
  • How do you add an existing user to the sudoers file?How do you add an existing user to the sudoers file?
  • Extend Your Linux Disk SpaceExtend Your Linux Disk Space
Tweet
Share
0 Shares
htaccess, Linux, nginx, redirect, web hosting

Comments are closed.

Proverbs 19:20

"Get all the advice and instruction you can, so you will be wise the rest of your life."

A Note On WordPress Hosting

Our main focus is of course .NET, but with a mix of Linux, virtualization, and other technologies. But if you're really looking for the best WordPress hosting specifically, read my WordPress host review to save yourself hassle AND money!




Recent Posts

  • What makes good web hosting?
  • jQuery Mobile C# ASP.NET and N5 Networks Software Repository
  • Open Source Bug Tracking Software and the Orchard Project
  • ASP.NET Development with Dreamweaver MX: Visual QuickPro Guide
  • Kendo UI Sample, ASP.NET Ajax Tutorial & More

Tags

ASP.NET Automation centos CMS css cytanium Development/Coding Email gmail Hosting htaccess http https IIS javascript Learning Linux logparser MySQL nginx openssl OrcsWeb performance PowerShell redirect RHEL security server SherWeb smtp SQL/Databases ssl System Administration telnet terminal tip Troubleshooting Ubuntu virtualization Visual Studio web farm web hosting Windows windows server Wordpress

Categories

  • ASP.net development
  • Development/Coding
  • Hosting
  • IIS (Internet Information Services)
  • SQL/Databases
  • System Administration
  • Virtualization
(c) ASPNETFAQ.com