[thelist] Rewrite https:// to http:// ??

sbeam sbeam at onsetcorps.net
Wed Apr 5 11:53:08 CDT 2006


On Tuesday 04 April 2006 01:45 pm, Colclasure, Wyett H wrote:
> 1. Reroute a user that typed https://address/file in the address bar 
to
> http://address/file
> 2. I can use rewrite rules to force specified pages to run on https 
but
> can't figure out how to get them back down to http outside of 
bypassing
> the PHP generated relative links with a hardcoded page

two ideas:

1) do it in PHP. this affects only .php pages (obviously) which may or 
may not be OK depending on your needs. I've been known to use 
auto_prepend_file to include a script that might include, among other 
things, a block like:

/** redirect to non-SSL page if we don't need it **/
if ($_SERVER['SERVER_PORT'] == 443 and
 !preg_match('/^\/secure\//' $_SERVER['REQUEST_URI'])) {

   header("Location: http://" . $_SERVER['HTTP_HOST']. 
$_SERVER['REQUEST_URI']);
   header("Connection: close");
   exit();
}

this has the advantage of allowing top-level images, css, etc called 
from pages within /secure/ to also go over SSL, avoiding the browser 
warning.

2) use mod_rewrite to do it based on subdomain name or directory name. 
Prob similar to what you are doing for the reverse direction.

<VirtualHost 64.140.206.28:443>
  ... SSL setup stuff ...
  RewriteCond %{SERVER_PORT} !^80$
  RewriteRule !^(secure/.*) http://domain.com/$1 [R,L]
</VirtualHost>

this might be faster (?) and cleaner. But you can get into a nice 
infinite redirect loop if not careful.

of course if you need to get more creative with the regexps then you 
can.

hth


-- 

# S Beam - Web App Dev Servs
# http://www.onsetcorps.net/



More information about the thelist mailing list