views:

71

answers:

2

Situation (directories tree) on an Apache server:

maindomain.com/
|
|_ .htaccess (just an empty file, no rule in here)
|
|_ addondomain1.com/
|  |
|  |_ .htaccess
|  |_ index.html
|
|_ addondomain2.com/
   |
   |_ .htaccess
   |_ index.html

Currently files in addondomain1.com can be viewed by going to:

http://www.addondomain1.com/index.html
http://www.addondomain1.com/
http://www.addondomain1.com
http://www.maindomain.com/addondomain1.com/index.html

I would like to redirect all requests:

http://maindomain/addondomain1.com/some/path/anypage.html (with or without 'www')

to same path/file but under addondomain1.com and always with 'www':

http://www.addondomain1.com/some/path/page.html

In order to try to accomplish this, I placed in maindomain.com/addondomain1.com/.htaccess this rule:

RewriteCond %{HTTP_HOST} !^www\.addondomain1\.com$ 
RewriteRule ^(.*)$ "http://wwww.addondomain1.com/$1" [R=301,L]

This one works almost great, and redirects well all the ones below:

http://addondomain1.com/index.html >> http://www.addondomain1.com/index.html
http://www.addondomain1.com/ >> http://www.addondomain1.com/
http://www.addondomain1.com  >> http://www.addondomain1.com
http://www.maindomain.com/addondomain1.com/index.html >> http://www.addondomain1.com/index.html
http://www.maindomain.com/addondomain1.com/ >> http://www.addondomain1.com/
http://maindomain.com/addondomain1.com/ >> http://www.addondomain1.com/

But unfortunately when going to:

http://maindomain.com/addondomain1.com
http://www.maindomain.com/addondomain1.com

NOTE both links above are WITHOUT final slash, it redirects to:

http://www.addondomain1.com//server/root/path/addondomain1.com

I think the regexp ^(.*)$ is getting "addondomain1.com" as part because the final slash is missing. Do you know how fix/workaorund this issue?

Thanks!

A: 
DirectorySlash Off
Wrikken
@Wrikken: but that's all?! :) I'm gonna try this and let you know, thanks!
Marco Demajo
@Wrikken: no, it does NOT wrok, I get exactly the same issue I was getting before. Thanks for the answer anyway
Marco Demajo
If not, can you enable your RewriteLog and give us a sample of what's happening? Also: why does this work: `http://www.main-domain.com/addon-domain-1.com/index.html >> http://www.addon-domain-1.com/index.html` as it wouldn't with your current setup: any other .htaccess rules we should know about?
Wrikken
A: 

Try this:

RewriteCond %{HTTP_HOST} !^www\.addondomain1\.com$
RewriteCond %{REQUEST_URI} ^/[^/]+/(.*)
RewriteRule ^ http://wwww.addondomain1.com/%1 [R=301,L]
Gumbo