XXX.YYY.com/ZZZ => www.hostdomain.com/?d=YYY&s=XXX&a

Using a single web hosting account to host multiple sites

XXX.YYY.com/ZZZ => www.hostdomain.com/?d=YYY&s=XXX&a

Postby kapo » Wed Jan 03, 2007 12:39 am

Hi,
I have been working on this for ages but cannot get it to work.
Basically I am trying to this:

XXX.YYY.com/ZZZ => www.hostdomain.com/?d=YYY&s=XXX&f=ZZZ

eg site.newdomain.com/foldername/ => www.hostdomain.com/?d=newdomain&s=sitename&f=foldername

'www' in front needs to be handled also. I use proxy redirect as I want the user to still see XXX.YYY.com/ZZZ in their browser.


I am sure this can be done with a simple rewrite statement.
This is where I am at:

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+\.[^\.]+)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://www\.hostdomain\.com/?d=%2&s=%1&f=$1 [P,L]



This does not work... any help is greatly appreciated!!
kapo
 
Posts: 6
Joined: Sat Dec 02, 2006 7:16 pm

Postby richardk » Wed Jan 03, 2007 9:11 am

'www' in front needs to be handled also.

Handled how? Please provide an example.

I use proxy redirect as I want the user to still see XXX.YYY.com/ZZZ in their browser.

Do the domains point to the same server and document root? If they do you won't need to proxy it.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^((.*)\.)?([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://www.hostdomain.com/?d=%3&s=%2&f=$1 [P,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby kapo » Wed Jan 03, 2007 4:19 pm

Thanks for you reply, unfortunately that did not work as expected...

www.YYY.com => www.hostdomain.com/?d=com&s=www.YYY&f=

XXX.YYY.com => http://www.hostdomain.com/?d=com&s=XXX.YYY&f=

XXX.YYY.com/ZZZ => http://www.hostdomain.com/?d=com&s=XXX.YYY&f=ZZZ

I have now come up with the following which 'almost' works:

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.hostdomain.com/?d=%3&s=%2&f=$1 [P,L]


:D WORKING!

XXX.YYY.com => http://www.hostdomain.com/?d=YYY&s=XXX&f=
XXX.YYY.com/ZZZ => http://www.hostdomain.com/?d=YYY&s=XXX&f=ZZZ
www.XXX.YYY.com => http://www.hostdomain.com/?d=YYY&s=XXX&f=
www.XXX.YYY.com/ZZZ => http://www.hostdomain.com/?d=YYY&s=XXX&f=ZZZ


:( NOT WORKING...

www.YYY.com or YYY.com

These go to: http://www.hostdomain.com/?d=com&s=YYY&f=
But need to be: http://www.hostdomain.com/?d=YYY&s=&f=
kapo
 
Posts: 6
Joined: Sat Dec 02, 2006 7:16 pm

Postby richardk » Thu Jan 04, 2007 11:43 am

Try:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?()([^\.]+)\.[^\.]+$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)\.[^\.]+$ [NC]
RewriteRule ^(.*)$ http://www.hostdomain.com/?d=%3&s=%2&f=$1 [P,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby kapo » Sat Jan 27, 2007 10:07 pm

Hi Richard,

Sorry for the late reply.. I have been on holiday camping in outback Australia! I have an exciting story about a savage goanna... but anyway...

The code still does not work. I get a 404 Page not found error if I don't provide a subdomain?

Using my previous rewrite I could probably write a workaround in the target page to account for the incorrect parameters... but where is the challenge in that!

I will keep on it. If you or anyone else has some other ideas please let me know!

Thanks! 8)
kapo
 
Posts: 6
Joined: Sat Dec 02, 2006 7:16 pm

Postby richardk » Sun Jan 28, 2007 12:49 pm

Try:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.[^\.]+$ [NC]
RewriteRule ^(.*)$ http://www.hostdomain.com/?d=%2&s=&f=$1 [P,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)\.[^\.]+$ [NC]
RewriteRule ^(.*)$ http://www.hostdomain.com/?d=%3&s=%2&f=$1 [P,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby kapo » Sun Jan 28, 2007 1:44 pm

No, that does not work.. all sorts of strange things happen.

My simple solution was to use my original rewrite:

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.hostdomain.com/?d=%3&s=%2&f=$1 [P,L]


And then just add this in the target file (.php)

Code: Select all
<?php

   // retrieve parameters

   $domain =    $_GET['d'];
   $subdomain = $_GET['s'];
   $folder =    $_GET['f'];
   
   // fix for mod_rewrite when no subdomain provided

   if ($domain=='com') {
      $domain = $subdomain;
      $subdomain = '';
   }

?>


Well, it does the job anyway! :wink:


Thanks for your help richardk.
kapo
 
Posts: 6
Joined: Sat Dec 02, 2006 7:16 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 61 guests

cron