LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Apache 2: forward http to https? (https://www.linuxquestions.org/questions/linux-software-2/apache-2-forward-http-to-https-279753/)

OneSeventeen 01-19-2005 11:24 AM

Apache 2: forward http to https?
 
I need to forward all requests from http://example.com to https://example.com

The site always starts on the same page (as it has only one function), so I have no need for elaborate rewrite scripts or anything, just basically any request to http://www.example.com/foo/bar/baz.php be forwarded to https://www.example.com/

I am using mod_ssl with apache 2 on a mandrake 10.0 machine.

I was thinking of adding:
Code:

RewriteEngine        on
RewriteCond          %{HTTPS} !=on
RewriteRule          .* - [F]

But I honestly don't know what that does, or if it would work (I just grabbed it from an ssl HOWTO on apache's site.)

Any tips?

OneSeventeen 01-19-2005 01:51 PM

We have a winner!
Code:

  RewriteEngine On
  RewriteCond %{SERVER_PORT} ^80$
  RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]

Works like a charm, and even does all the crazy url rewriting I didn't need, so if someone changed their current page, however deep into the app they are, to http:// it will automagically change it to https.

:D

I googled "apache rewrite http to https" to find it. ("Redirect" was just a bad word I guess, so after trying a few other searches, I finally found something.)

rino.caldelli 07-03-2006 07:10 AM

I use the code above in httpd.conf file but it doesn't work with my https server
I still have to use https://url
Any idea why the rewrite doesn't work???


All times are GMT -5. The time now is 05:26 AM.