Yet another Subdomain ReWrite

Using a single web hosting account to host multiple sites

Yet another Subdomain ReWrite

Postby dave@swb » Sat Apr 21, 2007 4:04 am

I have a good look at other posts but cannot work out what I need.

I am trying to acheive this

http://www.website.com/ to http://www.website.com/
but with
http://{subDir}/website.com/{page} to http://www.website.com/sub/{page}?dir={subDir}

I am using ?dir= for some PHP code.

I thought I was getting a dab hand at mod_rewrite and write simple urls easily, but this seems to be way out of my depth.

Any ideas??
dave@swb
 
Posts: 2
Joined: Sat Apr 21, 2007 3:59 am

Postby richardk » Mon Apr 23, 2007 10:17 am

You need DNS for the sub domains. All the sub domains need to go to your main docuement root (or the /sub directory with a slightly edited mod_rewrite).

In a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

Postby dave@swb » Wed Apr 25, 2007 3:16 am

Thanks for the reply, however we cannot get this to work.

On our server we can use http://test.website.com/ but are also available as http://www.test.website.com/ and http://www.website.com/test/

Does this give anyone else a better idea. Our hosting company is Total Choice Hosting BTW.

Thanks
Dave
dave@swb
 
Posts: 2
Joined: Sat Apr 21, 2007 3:59 am

Postby richardk » Wed Apr 25, 2007 5:29 am

The sub domains all have to go to the directory (/your/document/root/a/single/dircectory) containing the .htaccess (/your/document/root/a/single/dircectory/.htaccess) file, so test.domain.com to /your/document/root/a/single/dircectory and abc.domain.com to /your/document/root/a/single/dircectory etc.

If that is not what happens, you will need to ask your hosting company about it.
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 8 guests

cron