sub.domain.com/* -> domain.com/sub/* - rewrite

Using a single web hosting account to host multiple sites

sub.domain.com/* -> domain.com/sub/* - rewrite

Postby newbiewiz » Thu May 25, 2006 8:08 pm

heya guys...

i see there are a few close to wat i wanna achieve but not there yet i think..

i have a scenario here

i wanna have subdomains redirected to a folder including everything within the folder...

means for example

sub.domain.com -> domain.com/sub
sub.domain.com/duh.html -> domain.com/sub/duh.html
etc..

basically a subdomain with all the characteristics of a domain...

if possible ... www.sub.domain.com -> domain.com/sub as well

also the rule should match anything.domain.com ... means *.domain.com/* goes to domain.com/*/* ... cause i see some rules need to add the matching subdomain one by one.. which makes the htaccess file very long if i have like few hundred subdomains... hehe


of coz i need it to be url rewrite... dont wanna show them the real path in the address bar.. hehe... :)

thanks guys :)
newbiewiz
 
Posts: 6
Joined: Thu May 25, 2006 8:01 pm

Postby richardk » Fri May 26, 2006 3:42 am

One subdomain?
Code: Select all
RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule !^sub(/.*)?$ /sub%{REQUEST_URI} [QSA,L]


Replace "sub\.domain\.com" with the dubdomain (with the "."s escaped with "\"s).
Replace both "sub"s (on the RewriteRule line) with the directory name.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby newbiewiz » Fri May 26, 2006 4:43 am

thanks Richard

but i need something more universal.. which can support multiple subdomain..

which means as long as someone enter anything.domain.tld, it should look for domain.tld/anything...
and anything.domain.tld/folder/file.html should go to domain.tld/anything/folder/file.html

thanks Richard :)
newbiewiz
 
Posts: 6
Joined: Thu May 25, 2006 8:01 pm

Postby richardk » Fri May 26, 2006 4:51 am

From: http://forum.modrewrite.com/viewtopic.php?p=4453#4453.
Code: Select all
RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.DOMAIN$ [NC]
RewriteCond %1---%{REQUEST_URI} !^(.+)---/\1(/.*)?$
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]

Replace DOMAIN with your domain (without the www.).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby newbiewiz » Fri May 26, 2006 9:14 am

heya richard... thanks but it didnt work... 500 internal server error...
mabbe could it be due to the fact its apache 1.3.36 ?
newbiewiz
 
Posts: 6
Joined: Thu May 25, 2006 8:01 pm

Postby richardk » Fri May 26, 2006 9:30 am

Try this:
Code: Select all
RewriteEngine On

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

Postby newbiewiz » Fri May 26, 2006 9:39 am

this time no internal server error.. but .... hehe.. looks like the effect is as if the htaccess not there... all subdomain points back to the domain itself...
but if i type sub.domain.tld/something.html .. it will show 404 not found error and 500 error as well for error document handling
newbiewiz
 
Posts: 6
Joined: Thu May 25, 2006 8:01 pm

Postby richardk » Fri May 26, 2006 9:40 am

Try removing the "!" from this line:
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} !^$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby newbiewiz » Fri May 26, 2006 9:47 am

cool! looks like its working..

tested subdomain and also sub.domain.tld/index.html

if i call a file which does not exist it will say 404 which is correct...

but was wondering.. is the htaccess you construct for me can build in with ability to deal with 404 500 403 errors? :D

thanks a lot Richard!!! :)

have a nice day...
newbiewiz
 
Posts: 6
Joined: Thu May 25, 2006 8:01 pm

Postby richardk » Fri May 26, 2006 9:53 am

You probably want ErrorDocument.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 68 guests

cron