Splitting single root dir with mod_rewrite

Splitting single root dir with mod_rewrite

am 17.01.2008 15:42:44 von Ken C

Hi Folks,

I've been tasked with moving a website from a host which used two
separate root directories, one for http and a second one for SSL (https)
requests, to a host which has only one root directory for both. To save a
lot of work modifying the app, I'd like to simply use mod_rewrite to emulate
having separate root dirs. In addition to the split, there is an existing
requirement that requests which do not begin with www. be externally
redirected to include that sub domain.

In the webroot, I'll create two directories, "www" and "secure". Here's
my first attempt at the .htaccess file which will reside in the webroot.
Will it work or am I missing something obvious (eg a simpler, better way to
do it?). Please note that I'm intentionally trying to prevent any access at
all to the actual webroot directory on the new host.

############# begin .htaccess
RewriteEngine On

# external redirect for all hosts which do not begin with www.
RewriteCond %{SERVER_NAME} ^[^wW]
RewriteRule ^(.*)$ http://www.domainname.com/$1 [redirect=permanent]

# split single webroot into two subdirs
RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ /secure/$1
RewriteRule ^(.*)$ /www/$1
############# end .htaccess

Your input is appreciated. Thanks.
--

>> Ken Clarke
>> Contract Web Programmer / E-commerce Technologist
>> www.PerlProgrammer.net