Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite before SSL

Rewriting url before browser gets to ssl cert

         

Cactard

1:36 am on Feb 5, 2008 (gmt 0)

10+ Year Member



Hello all. I have a problem I am trying to deal with around mod-rewrite.

I have apache serving up sites for a dozen domains using virtual hosts that do both http and https. Users get to each site over http, but there are several links that will direct their browser to the same site but over https to protect the traffic. All of the sites go to the exact same webroot, but the content (fed from a database) looks a little different based on which site the user is going to.

My problem lies in the fact that sometimes people come to the site via domain.com instead of www.domain.com, which works fine until they click on one of the links that take them over to the 'secured' version of the site. The SSL cert is tied to www.domain.com, so when they are headed for domain.com (without the hostname) the browser prompts them with the "invalid certificate" error.

So what I am attempting to do is rewrite the url to add the hostname (or correct it) before apache feeds them the SSL certificate.

This brings me to an even more basic question. This is my first foray into mod-rewrite and I am not seeing any effect from ANY rules I am attempting. From another post I put this into my httpd.conf file, but I'm getting a 404 error because foo.html is not found.

RewriteEngine On
RewriteRule ^foo\.html$ [webmasterworld.com...] [R=301,L]

There is a line loading the module for mod-rewrite:
LoadModule rewrite_module modules/mod_rewrite.so

Any comments, thoughts, or troubleshooting tips are welcome and appreciated.

Dave

jdMorgan

2:37 am on Feb 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need a cert for example.com if you want to avoid the invalid cert problem. For security reasons, redirects prior to authentication are not permitted.

The syntax of the RewriteRule pattern changes between server config files (httpd.conf, conf.d, etc.) and .htaccess in directories and subdirectories; In the server config files, the pattern must contain the full URL-path, whereas in .htaccess, the pattern must match only that part of the URL-path that remains after the path to the current directory (in which this rule within the .htaccess file resides) is removed.

In English, that means that for a URL-path of /foo/bar/woot.html, the pattern in the various files would be:

in file: .. RewriteRule pattern
httpd.conf ^/foo/bar/woot\.html$
/.htaccess ^foo/bar/woot\.html$
/foo/.htaccess ^bar/woot\.html$
/foo/bar/.htaccess ^woot\.html$

Short answer: Stick a leading slash on your pattern. :)

Jim