Link to home
Create AccountLog in
Avatar of dealclickcouk

asked on

Managing subdomain redirects

We manage individual servers in our cluster by giving each a subdomain which stats its role;


To enable hotswaps and clustering etc all servers are configured the same, but for example the admin. server will also have additional backend administation software...

The problem is that we access the admin back end by, but for some reason we now have and results in google serps.

I would like away to redirect visitors to www. but still allow access to

I thought a 301 redirect in .htaccess would do the trick (ah yes the servers are apache!), but I'm not sure of the syntax to make sure it doesn't redirect visitors to the /admin/ directory.

Avatar of McKirk
Flag of Germany image

I guess there is a easier way.

Your apache config has the entry "documentRoot". This is, where your "website" is saved. In that directory is the subdirectory "admin".
You just could put a simple PHP file in the documentRoot with this content:


That means, that every request to will be redirected to, but request to any subdirectory (like will not be affected.

Of course you will have to have PHP working.
Avatar of dealclickcouk


Ah ok, but the domain use apache rewrite, so how would that be effected....

should go to:

should not redirect anywhere...

I think your redirect would just work for a single domain redirect, rather than retain mod_rewrite path?

Okay, you're right. Sorry.

Try this:

RewriteCond %{HTTP_HOST}   !^www\..* [NC]
RewriteCond %{HTTP_HOST}   !^.*\admin [NC]
RewriteRule ^(.*)          http://www.%{HTTP_HOST}/$1 [R=301]

This is redirecting all request without www at the beginning and without /admin as first directory to www.domain&
ok tried that doesn't seem to work still displays the page on the admin server


gives a file not found error (because I removed the redirect stuff in the .htaccess file and replaced with your code above)

Check, if your apache's conf does allow configuration within htaccess files.

yes, because it was already using .htaccess for redicts and cache settings.
OK two things have got us closer...

First I added:  RewriteEngine On, but then still got a page not found error...

Second, viewed the url with SeaMonkey which gives a much nicer error: could not be found. Please check the name and try again.

note the admin. had not been removed, just www. added, so if the .htaccess can be tweaked to remove this then we have a winner
Okay, we'll try one after another.

First the redirection of ALL from admin.* to www.*

RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$$1 [L,R=301]  

Please confirm, that this do redirect ALL trafic from admin to www (after replacing with your domain :-)).
nope that doesn't work, now I see the pages on the admin server
Sorry, my mistake:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$$1 [L,R=301]  

It should redirect all pages WITHOUT www at the beginning, not WITHOUT admin (like it my last post).
ok great that works for the normal www. redirect, but not for the /admin/ ie that is still redirected.
So I guess another condition is required?
Okay, good so far.

Nor we add the second condition:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST}   !^.*/admin [NC]
RewriteRule ^(.*)$$1 [L,R=301]  

I meant NOW not nor and please pay attantion to the slash (not a backslash!).
nope, that still redirects the /admin/... stuff to www.
Avatar of McKirk
Flag of Germany image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
perfect, many thx
thx for all your help and hand holding, cant have been easy ;)