simple -> wildcard sub domains to subfolder

Using a single web hosting account to host multiple sites

simple -> wildcard sub domains to subfolder

Postby marchello » Wed Oct 01, 2008 5:45 am

Hi all,

I would like to know if someone can help me do this simple redirect. I tried at least 7 examples i found here but i couldnt make it work. First of all i have mod_rewrite enabled and *.mydomain.com DNS configured to point to same DNS as the www.

Im using codeigniter so it would be great to leave the rules i already have:

Code: Select all
Options +FollowSymLinks
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]



what im trying to achieve is simple:


anything.domain.com

-> should point ( if possible mask )

www.domain.com/index.php?/profile/anything

and also:

anything.domain.com/stats/12/.. ( etc )

-> should point ( if possible mask )

www.domain.com/index.php?/profile/anything/stats/12/..


Thanks in advance!!
marchello
 
Posts: 7
Joined: Sun Feb 11, 2007 10:24 am

Postby richardk » Wed Oct 01, 2008 10:56 am

What happens currently when you go to the sub domains? Do you see the same as when you go to your main domain?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ /index.php?/profile/%1 [L]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby marchello » Wed Oct 01, 2008 12:28 pm

Thanks for the quick response richardk.

Yes I tried the code you provided me and i still see same thing as homepage. what could be causing this?
marchello
 
Posts: 7
Joined: Sun Feb 11, 2007 10:24 am

Postby richardk » Wed Oct 01, 2008 12:52 pm

Do the other URLs work?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /index.php?/profile/%1/$1 [L]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby marchello » Wed Oct 01, 2008 1:28 pm

thanks again :)

The normal URLs work perfectly, like www.example.com/whatever

the problem is that the subdomains seem to be treated as the actual normal domain the www.

if i go to:

username.example.com it shows
www.example.com

and if i go to:

username.example.com/whatever it shows the same as
www.example.com/whatever

In my hosting account i have been told i have Wildcard DNS enabled,
under my domain i have both:

www.example.com and *.example.com DNS pointing to the same ip ( static IP )

The server configuration settings is the following:

Image
marchello
 
Posts: 7
Joined: Sun Feb 11, 2007 10:24 am

Postby richardk » Wed Oct 01, 2008 2:38 pm

Try adding
Code: Select all
ServerAlias *.example.com


You also seem to have a closing </IfModule> without a start <IfModule>.
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 19 guests

cron