[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: forcing http to go to https



At 08:30 PM 6/24/2004, Steven Stern wrote:
I've worked around all of it by deleting all the webmail virtualhosts and PHP
redirects and putting this at the start of the VirtualHosts list:

Allow me to suggest a different approach, and one which has been working on my server for a while now.


<VirtualHost *>
    ServerName     www.domain.com
    ServerAdmin    webmaster domain com
    DocumentRoot   /var/www/domain

    RewriteEngine  on
    RewriteCond    %{SERVER_PORT}  !^443$
    RewriteRule    ^/(.*)          https://%{SERVER_NAME}/$1 [L,R,NC]
</VirtualHost>

What this does is act on any connection which does not come in on port 443. That part is obvious. The neat thing is that it then takes everything in the URL after the first slash with the (.*) and remembers it as $1. By "after the first slash" I mean after the slash at the end of http://www.domain.com/ <-- that last slash. So everything after that slash, that is the internal URL, is memorized. The URL is then rewritten as https://www.domain.com/$1 where "www.domain.com" came from the SERVER_NAME httpd variable and $1 is the internal URL as memorized earlier. I don't remember what the L,R,NC do... read the httpd docs! <grin>

Result: *any* page on your site will then be immediately and forcibly redirected to the very same URL but over the secure connection. Works *beautifully*.


-- Rodolfo J. Paiz rpaiz simpaticus com http://www.simpaticus.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]