Books - Freelance - Buy PSP - Facebook Proxy - Outsource

PDA

View Full Version : Automatically generate subdomains


halifaxx
Feb 16th 2008, 7:57 am
Hi all,


I would like to automatically generate subdomains when a user registers.
Unfortunately i know very little (jack sh*t) about mod_rewrite and .htaccess etc.

But my plan is to open .htaccess with PHP when the user subscribes, and add some lines to make http://user.test.com refer to http://www.test.com/users.php?id=1 for example.

Is this a good idea and if possible, can someone tell me what lines PHP has to write in .htaccess.


Thx a lot!!

marksailes
Feb 17th 2008, 8:28 am
if you have access to the apache httpd.conf have a google for virtual hosts

buldozerceto
Feb 17th 2008, 2:53 pm
.htaccess code


RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ! ^www\.test\.com [nc]
RewriteCond %{HTTP_HOST} (.*)\.test.com [nc]
RewriteRule /users.php?id=1%

halifaxx
Feb 24th 2008, 10:33 am
.htaccess code


RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ! ^www\.test\.com [nc]
RewriteCond %{HTTP_HOST} (.*)\.test.com [nc]
RewriteRule /users.php?id=1%



ill try that!

halifaxx
Feb 24th 2008, 10:58 am
i've got this code now:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^www.$
RewriteRule ^(.*)$ http://www.allsites.be/~test/index.html [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.test\.be
RewriteCond %{HTTP_HOST} ^([^.]+)\.test\.be
RewriteRule ^/?$ http://www.test.be/index.php?id=%1 [L]

www.test.be itself refers to www.allsites.be/~test.

but when i type frank.test.be it doesn't refer to www.test.be/index.php?id=frank

it just says "Could not found server frank.test.be"

help! :D (im such a noob at this)

sweetfunny
Feb 26th 2008, 10:19 am
You cant just add a rewrite you need to configure wildcard subdomains on your server like *.test.com so then * can be anything and generated on the fly.

halifaxx
Feb 27th 2008, 1:38 pm
You cant just add a rewrite you need to configure wildcard subdomains on your server like *.test.com so then * can be anything and generated on the fly.

Thx, got it to work now, but i can see the redirect. I'd like to keep the subdomain URL in the adres bar unchanged! (invisible redirect) this is the code i use now:

Options +FollowSymLinks

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^www.$
RewriteRule ^(.*)$ http://www.digx.be/~wieper/index.php [R=301,L]

RewriteCond %{HTTP_HOST} !^w{3}\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.wieper\.be$
RewriteRule ^(.*)$ http://www.digx.be/~wieper/index.php?p=bedrijvengids&show=detailed&sub=%1 [L]

You can see that there is already a redirect from the site domain i'm using to my main domain.

When i go to http://visionline.wieper.be i go to http://www.digx.be/~wieper/index.php?p=bedrijvengids&show=detailed&sub=visionline
which is just like http://www.wieper.be/index.php?p=bedrijvengids&show=detailed&sub=visionline
But i want to keep http://visionline.wieper.be as URL? Or at least the www.wieper.be domain and not the digx domain.

halifaxx
Mar 6th 2008, 9:25 am
nobody? :)