views:

357

answers:

5

Hello,

I have been looking for a while now to find a solution to accomplish the following system.

I would like to build a PHP system on, let's say, domainA. On this domainA I will allow an administrator to 'create' a new website. This website contains only of pieces of text, which are all stored in a database. This, I know how to do.

However, now I would like to make it possible that visitors that surf to domainB will be invisibly redirected to for example domainA.com/gateway.php?refdomain=domainB&page=xxx or something similar. I have a vague idea this should be done by .htaccess, but I don't really know how I can do this in the most easy way. If for example there are some POST or GET requests on domainB, this should keep working. Also images linked to http://www.domainB.com/test.gif should be invisibly loaded form www.domainA.com.

I also know there are some CMS systems (eg drupal) which allow this feature, so it is possible, I just don't know how.

Thank you for any advice that might point me in the right direction, kind regards, Digits

A: 

You could use the redirect header..

Thomaschaaf
A: 

If you use a CMS like Drupal, you should be able to assign these using the Portal Alias. By using the alias you will be able to assign different domains to point to different "sites" that are created.

TheTXI
I think he's trying to avoid using a CMS.
Ben S
+2  A: 

Are you hosting both of these on the same machine? If so, something like VirtualHosts in Apache could solve this for you.

mod_alias and mod_rewrite might also be of some use to you.

Ben S
Apache VirtualHost has something like ProxyPass and ProxyPAssReverse which can be used to define multiple VirtualHosts with Apache acting like a Router. Im sure it works for static domains, not exactly sure if it'll work for "creating" domains like mentioned in the question
Sathish
Well, you can't "create" a domain anyways... you have to go register it. As part of the registration, just point it to the same IP as domainA. The VirtualHosts will take care of the rest if you configure it correctly.
rmeador
Thank you for this suggestion, however, I think if I use Virtualhosts, I will need to copy the files to each ftp account of that website. My goal is to run several sites (domains) and only to maintain one account with files. All data is stored in a database, not in files.
Digits
A: 

Basically, you'll want to point all your domains to the same directory (maybe using a wildcard in your vhosts) and then setup urlrewrite; look at this question for an example, and it can be in a .htaccess file or Apache configuration.

All requests that come in will go to the same gateway.php and you can extract the current domain and requests using $_SERVER['REDIRECT_QUERY_STRING'], $_SERVER['REQUEST_URI'] and $_SERVER['SERVER_NAME'] for example. See $_SERVER. You'll then be able in your gateway.php to send the correct files.

lpfavreau
This won't change the URL in the address bar of the browser, it is transparent to the user.
lpfavreau
A: 

OK, here's a really simple example:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domainA\.com
RewriteRule (.*) http://www.domainA.com/gateway.php?realpath=$1 [L,QSA]

You could then parse "realpath" in your gateway script using parse_url and take the appropriate actions.

You could get more complex with your rewrite rules to have separate ones for images, etc. if you wanted to

Eric Petroelje
When you use these types of rewrite rules, does it actually change the address in the users browser? Does it do a 301 redirect? That would be undesired, I think. I would hope it would handle it all internally within the server. Please advise, I am quite curious.
Josh Stodola
I think this could work! I used somthing similar but I did not realize it could be used across domains. I will definately try this. Thank you!
Digits
@Josh - no, it does not do a 301 redirect (well, it could if you wanted it to, but as written it wouldn't). It's strictly an internal redirect. The browser never sees the new URL
Eric Petroelje