Subject: HTTP --> HTTPS rewrite not working

From: "Sancho2k.net Lists" <[email-masked]>
Date: Fri, 17 Jan 2003 21:39:12 -0700

Greetz all,

I'm trying to force one of my virtual hosts to use https when http is 
requested by a mod_rewrite rule. I am testing the implementation using 
curl.

When I specify https in my url, curl will grab the correct page:

[root@molodetz:~]# curl https://family.sancho2k.net

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Sancho2k.net Family - Our family web page</title>

But when I throw http://family.sancho2k.net ...

[root@molodetz:~]# curl http://family.sancho2k.net
<html><head><meta http-equiv="refresh" content="0; 
URL=http://www.sancho2k.net/index.php"></head></html>

This is my VirtualHost configuration:

NameVirtualHost 10.0.0.40:443
<VirtualHost 10.0.0.40:443>
     ServerName                  family.sancho2k.net
     DocumentRoot                /var/www/htdocs/fam_public_html
     ServerAdmin                 [email-masked]
     CustomLog                   logs/family/access_log combined
     ErrorLog                    logs/family/error_log
     TransferLog                 logs/family/ssl_access_log
     LogLevel                    debug
     SSLEngine                   on
     SSLCertificateFile          /var/www/conf/certs/family/server.crt
     SSLCertificateKeyFile       /var/www/conf/certs/family/server.key
     UseCanonicalName            off
     RewriteEngine               on
     RewriteCond                 %{SERVER_PORT}   !^443$
     RewriteRule                 ^/(.*)   https://%{SERVER_NAME}/$1 [L,R]
     #SSLVerifyClient            require
     #SSLVerifyDepth             1
     #SSLCACertificateFile       conf/certs/cacert.crt
</VirtualHost>

Why is it redirecting my requests to www.sancho2k.net? This is a 
seperate virtual host I have set up:

NameVirtualHost 10.0.0.2:80
<VirtualHost 10.0.0.2:80>
     ServerName                  www.sancho2k.net
     DocumentRoot                /var/www/htdocs
     ServerAdmin                 [email-masked]
     SSLEngine                   off
</VirtualHost>

Thanks in advance for help.

DS

______________________________________________________________________
Apache Interface to OpenSSL (mod_ssl)                   www.modssl.org
User Support Mailing List                      [email-masked]
Automated List Manager                            [email-masked]

---

From: "Jeff" <[email-masked]>
Date: Sat, 18 Jan 2003 17:10:32 +1000

Well, you have the ReWrite rule INSIDE the destination SSL VH config..  A
bit useless..

The ReWrite needs to be inside the VH configs that NEED to redirect - such
as 10.0.0.40:80, Servername family.sancho2k.net

As for why http://family.sancho2k.net is sending a webpage with a meta-tag
redirect - What is actually being server for that address ???
It is probably your default page you have put there..

Rgds
Jeff

---

From: Mads Toftum <[email-masked]>
Date: Sat, 18 Jan 2003 11:29:48 +0100

> <VirtualHost 10.0.0.40:443>
[SNIP]
>     RewriteCond                 %{SERVER_PORT}   !^443$

This will never happen because you're already inside the Port 443
vhost container. 
>     ServerName                  www.sancho2k.net

Redirect / https://family.sancho2k.net

No real need to use mod_rewrite for that.

vh

Mads Toftum
-- 
`Darn it, who spiked my coffee with water?!' - lwall

---

From: "Sancho2k.net Lists" <[email-masked]>
Date: Sun, 19 Jan 2003 15:55:55 -0700

> This will never happen because you're already inside the Port 443

Stupid oversight on my behalf. Thanks to those that pointed this out.

> No real need to use mod_rewrite for that.

And it works with the simple redirect. Surprisingly, most of the howtos 
and internet resources I find suggest using mod_rewrite to direct all 
requests to the SSL site. Thanks for the clarification.