HTTPS redirect to HTTP

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

HTTPS redirect to HTTP

Post by alex.barylski »

The site I am currently working on was at one time completely behind SSL.

Search engines have picked up some pages and now when you click a link the page is dead because SSL has now been disabled.

Is there a simple way I can add an directive to .htaccess to basically redirect the SSL request onto a non-SSL request.

The pages exist but cannot be accessed via HTTPS but Google has now cached the pages as HTTPS so ideally whenever someone clicks a link on Google (Yahoo, whatever) which is HTTPS they are simply redirected to the HTTP version instead.

I assume this is a simple one liner? Can you show me an exmaple please :)

Code: Select all

 
RewriteEngine On
 
#RewriteCond %{HTTP_HOST} !^www\.domain\.com$
#RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
 
php_value session.cookie_domain ".domain.com"
 
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 
I am trying to force a redirect to http://www.domain.com in case the user enters without sub-domain as well. The last bit of uncommented code doesn't work either.

Cheers,
Alex
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: HTTPS redirect to HTTP

Post by pickle »

An .htaccess file will only be invoked if a request for a file is received. If the user is requesting a page via https (port 443 by default), and your webserver is only listening for http (port 80 by default) connections, the two will never meet and the .htaccess file will never be invoked. You can set Apache up to listen on 443, but I don't know what needs to be done with regards to encryption, even if it is just a simple forward.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply