views:

216

answers:

2

Hi I'm quite new to PHP... And need something to do as fast as I can..

I have some clients within the "clients" directory like here... "http://domain.com/clients/client0001/fluids/..."

I want this URL to be shown in the address bar like this.

"http://client0001.domain.com/fluids/..."

with the help of .htaccess. Any help will be appreciated ...

Thanks

+1  A: 

You can use mod_rewrite to rewrite such URLs:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$
RewriteRule !^clients/ clients/%1%{REQUEST_URI} [L]

But your webserver needs to be configured so that it accepts such host names and sends the requests to the proper virtual host.

Gumbo
I'm using Mediatemple's grid service hosting. I 've tried to remove www prefix and it worked. Does that mean above code will work or not, Gumbo ..
Jucora
Didn't worked out.
Jucora
A: 

I've used this before as posted by Gumbo.

Only issue I've had with it is that you can't then use further rewrite rules - so if the site you are serving on the subdomain uses url rewriting, you have to make it its own virtual host.

benlumley