Dynamic Subdmains

Using a single web hosting account to host multiple sites

Postby richardk » Wed Jul 12, 2006 4:53 am

.htaccess forwards to mydomain.com

By forward do you mean a visible redircet, or internally without the user knowing? If the domains point to subdirectories, you probably can't have an internal redircet.

I want to use a similar php script on my index page, so when a user hits :
ANYSUBDOMAIN.mydomain.com

Only for your index, what about ANYSUBDOMAIN.mydomain.com/stuff/here?

The subdomain's folders doesn´t exist, and i dont want to create them dynamically neither, i just want to know the name of the subdomain they are typing.


This might work, it depends on the server configuration:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.+)\.DOMAIN$ [NC]
RewriteRule ^(.*)$ http://DOMAIN/index.php?sub=%1&uri=$1 [R=301,L]


But if you're getting a forbidden error, it might mean the subdomain's arn't setup in the main server configuration and then you need to ask GoDaddy about it. Ask them if they can point all your subdomains to your main document root.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby BADGROOVY » Wed Jul 12, 2006 8:39 am

By forward do you mean a visible redircet, or internally without the user knowing? If the domains point to subdirectories, you probably can't have an internal redircet.


Internally without the user knowing, i want them to see on the url:

SUBDOMAIN_TYPED_BY_USER.mydomain.com

But i want them redirected to : mydomain.com
(where i have an index.php catching the subdomain name.)


Only for your index, what about ANYSUBDOMAIN.mydomain.com/stuff/here?


I just catch the subdomain with te php script and ignore /stuff/here
This might work, it depends on the server configuration:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.+)\.DOMAIN$ [NC]
RewriteRule ^(.*)$ http://DOMAIN/index.php?sub=%1&uri=$1 [R=301,L]


I made a subdomain "test",using the cpanel to test it.
It worked when typing test.mydomain.com

I got php?sub=test&uri=test

Exactly what i wanted,But still forbidden error with any other subdomain not created with cpanel.

But if you're getting a forbidden error, it might mean the subdomain's arn't setup in the main server configuration and then you need to ask GoDaddy about it. Ask them if they can point all your subdomains to your main document root.



They told me that my full server path was this:

/home/content/B/A/D/BADGROOVY/html

I´m going to ask them abput pointing teh subdomains to my main document root.

Look i found a web page that works very similar to what i achieve.

The domain name is : www.esgay.com
But if you type any subdomain.esgay.com

http://badgroovy.esgay.com/

It´s page in spanish, but you can get the trick easy.


It seems that with a php script they catch the subdomain typed, and use it as a joke to tease the user.


THKS. :)
BADGROOVY
 
Posts: 6
Joined: Tue Jul 11, 2006 7:47 pm

Postby richardk » Wed Jul 12, 2006 9:17 am

Look i found a web page that works very similar to what i achieve.
...
It´s page in spanish, but you can get the trick easy.

I understand what you want to achieve, but it's not just mod_rewrite. You need DNS (which i think you have already) to get the request to the server, server configuration to send the subdomain to your main document root where the .htaccess is, then the mod_rewrite.

Without the subdomains pointing to your main document root i don't think this can be done.

The mod_rewrite could be changed so it ignores www. and the URI:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

Postby BADGROOVY » Thu Jul 13, 2006 8:53 am

Hi again, well goddaddy just started ignoring my emails.

Anyways i had another hosting company named xstreamhost, i told them what i needed with the DNS, and they fixed it right away.

Now im just playing with the htaccess and php scripts, to achieve what i want.

Thanks for the tips and your support richardk. :P
BADGROOVY
 
Posts: 6
Joined: Tue Jul 11, 2006 7:47 pm

Postby uoitguy » Sun Jul 16, 2006 1:28 pm

I came across this thread because I was hoping to do something similar. I have tried configuring .htaccess with the following rule. The redirect works, but the values of sub and uri are not passed to the PHP script. Also, I would like to pass the value of the page selected on the current subdomain. (i.e. create a GET variable called page for index.php)

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.+)\.DOMAIN$ [NC]
RewriteRule ^(.*)$ http://DOMAIN/index.php?sub=%1&uri=$1 [R=301,L]


Thanks!
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

Postby richardk » Mon Jul 17, 2006 3:40 am

The redirect works, but the values of sub and uri are not passed to the PHP script.

You're using exactly (with DOMAIN replaced) what you pasted and you don't see the GET variables in the URL? there's no way it should redirect but not pass the variables (at the very least they'd be empty, but only uri can be empty), unless you have something else causing the redirect and mod_rewrite isn't involved.

Also, I would like to pass the value of the page selected on the current subdomain. (i.e. create a GET variable called page for index.php)

That's what uri is.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby uoitguy » Mon Jul 17, 2006 4:43 am

Okay, thanks richardk. I'll keep fiddling with everything. Thanks for your help :)
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

Postby uoitguy » Wed Jul 19, 2006 10:11 am

Okay, I have updated my .htaccess in the subdomain to include the following:

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)\.DOMAIN$ [NC]
RewriteRule ^(.*)$ /index.php?sub=%1&uri=$1 [L]


Now I am getting a 500 error when I try to connect to the subdomain. Any more suggestions?
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

Postby richardk » Wed Jul 19, 2006 10:59 am

It's going into a loop because .* matches index.php, add
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

above your RewriteCond.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby uoitguy » Wed Jul 19, 2006 11:08 am

I am still getting the same error. Any other suggestions? I apologize, but I have zero experience with mod_rewrite and very little experience with reg exps. Thanks richardk!
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

PreviousNext

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 95 guests

cron