anything.domain.com/* to domain.com/anything/*

Using a single web hosting account to host multiple sites

anything.domain.com/* to domain.com/anything/*

Postby webdev9999 » Thu Apr 12, 2007 5:10 am

I'm new to php and i'm interested in knowing about mod_rewrite..

I tried searching related topics but can't understand.

Can anyone give me a simple example

My task is to acheive the following
anything.domain.com/* to domain.com/anything/*

That is

anything111.domain.com/* to domain.com/anything111/*
anything222.domain.com/* to domain.com/anything222/*
anything333.domain.com/* to domain.com/anything333/*

...
...
...

anythingnnn.domain.com/* to domain.com/anythingnnn/*

Thank u...
webdev9999
 
Posts: 2
Joined: Thu Apr 12, 2007 4:49 am

Postby richardk » Thu Apr 12, 2007 11:23 am

You have to have DNS for the sub domains. These sub domains need to point to the main domains document root.

Then try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /%2/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 23 guests

cron