NameSilo

How would you do this?

Spaceship Spaceship
Watch

lpxxfaintxx

Established Member
Impact
13
Hi,

I was wondering how a site can offer a free subdomain. For example, at www.uni.cc, they give out free subdomains (yoursite.uni.cc). I was wondering how I can do that too with my domain, cfg.in. Is it possible?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
It is possible, but if I'm reading you clearly, you want a script that will automate the process of making a subdomain instead of you manually creating the subdomain, yes? If so, then I'm not quite sure if it is possible. However, if you need help with the manual method, I'll be more than happy too. :)
 
0
•••
Lol, manually would be easy with cPanel. I'm looking for an automated way, like uni.cc has.
 
0
•••
lpxxfaintxx said:
Lol, manually would be easy with cPanel. I'm looking for an automated way, like uni.cc has.

True enough. Now, I'm not 100% sure about this method, but try it and see what happens. You'll need your php script to write an entry to your .htaccess file containing this text.

Code:
RewriteCond %{HTTP_HOST} subdomain.example.com $ [NC]
RewriteCond %{REQUEST_URI} !/subdomain_directory/
RewriteRule ^(.*)$ subdomain_directory/$1 [L]

Substitute subdomain.example.com with the user's subdomain and your domain, and the /subdomain/ part with the user's subdomain. You would have to open the .htaccess file with php's file-writing functions (I'll just use the functions that I'm familiar with):

Code:
<?php

$_htfile = fopen(".htaccess", "a");
fputs($_htfile, <htaccess text>);
fclose($_htfile);

?>

I hope this helped you out abit.
 
Last edited:
1
•••
Thanks, I'll try it out later when I get home. Hope it works!

edit: Before I try it out, is there any way so that I can set up a redirection, instead of a directory?
 
0
•••
lpxxfaintxx said:
Thanks, I'll try it out later when I get home. Hope it works!

edit: Before I try it out, is there any way so that I can set up a redirection, instead of a directory?

Honestly, I don't know. I suggest just trying it out with directories first, and then if it works, we'll look into redirection. I guess if you can somehow get the subdomain url as a variable from the .htaccess file, you can plug it into a header() function, but one step at a time. I'm also learning since I don't exactly know how to go about this.
 
0
•••
Hrm, let me test it out some more. Right now, it's causing "Internal Server Error 500"s..
 
0
•••
1
•••
0
•••
Glad you find the script you were looking for.
Man_In_The_Box's suggestion of using mod_rewrite to redirect sub-domains to directories is also a clever solution.
 
0
•••
Appraise.net

We're social

Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back