Francesco
Francesco

Reputation: 25259

Redirect different domains pointing to same server to different version of same website

I have different domains say like (fictious names) "plumbers.org" and "cleaning.org" pointing to the same folder in my apache2 conf. and the main domain is "workers.org"

what i want to obtain is basically to have plumbers.org pointing to workers.org/index.php?version=1

and to have cleaning.org pointing to workers.org/index.php?version=2

is something I set in my .htacess? what's best practice?

Upvotes: 1

Views: 191

Answers (2)

anubhava
anubhava

Reputation: 785551

Assuming all 3 domains point to the same DocumentRoot folder, you can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)plumbers\.org$ [NC]
RewriteRule ^/?$ index.php?version=1 [L,QSA]

RewriteCond %{HTTP_HOST} ^(?:www\.)cleaning\.org$ [NC]
RewriteRule ^/?$ index.php?version=2 [L,QSA]

Upvotes: 1

Axalix
Axalix

Reputation: 2871

You can try to add a permanent redirect in the original httpd / apache conf file, e.g.:

<VirtualHost ...>
    ServerName plumbers.org
    Redirect 301 / http://workers.org/index.php?version=1
</VirtualHost>

...

<VirtualHost ...>
    ServerName cleaning.org
    Redirect 301 / http://workers.org/index.php?version=2
</VirtualHost>

Technically, it should also work if you put these changes in the corresponding .htaccess files (if .htaccess files are not prohibited by the "parent" conf). Without <VirtualHost> section, of course, then.

Upvotes: 1

Related Questions