XXX.hostdomain.com/YYY/ => www.hostdomain.com/index.php?d

Using a single web hosting account to host multiple sites

XXX.hostdomain.com/YYY/ => www.hostdomain.com/index.php?d

Postby os4ever » Wed Aug 29, 2007 8:15 am

Hi,

i want to achieve XXX.hostdomain.com/ => www.hostdomain.com/index.php?s=XXX
AND XXX.hostdomain.com/YYY/ => www.hostdomain.com/index.php?d=YYY&s=XXX

i 've read the topic in :http://forum.modrewrite.com/viewtopic.php?t=2671
but i don't want to change the hostdomain,and i also need to achieve the two situations.


Please if some one can help me,I'm new to url rewriting .Thx a lot
os4ever
 
Posts: 3
Joined: Wed Aug 29, 2007 5:46 am

Postby richardk » Wed Aug 29, 2007 3:15 pm

You need DNS for the sub domains and they need to go to your document root. Then 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} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ /index.php?s=%1 [QSA,L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.+)$ /index.php?s=%1&d=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby os4ever » Thu Aug 30, 2007 12:15 am

Thanks a lot richardk,
I tried the code but it works only for :www.domain.com/index.php?s=XXX and when i just use this part of code:
Code: Select all
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ /index.php?s=%1 [QSA,L]

AND i don't know why it doesn't work for the other part:
AND XXX.domain.com/YYY/ => www.domain.com/index.php?d=YYY&s=XXX

the code was:
Code: Select all
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.+)$ /index.php?s=%1&d=$1 [QSA,L]


i thinks that it's due to $1?
os4ever
 
Posts: 3
Joined: Wed Aug 29, 2007 5:46 am

Postby os4ever » Thu Aug 30, 2007 7:42 am

i think that i should use this syntax:
Code: Select all
RewriteRule ^([a-z-]+)/$ /index.php?s=%1&d=$1 [QSA,L]
os4ever
 
Posts: 3
Joined: Wed Aug 29, 2007 5:46 am

Postby richardk » Thu Aug 30, 2007 3:54 pm

Or you can use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ /index.php?s=%1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.+)$ /index.php?s=%1&d=$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 94 guests

cron