kmzacks Posted October 27, 2007 Posted October 27, 2007 Howdy all; is there any way I can set up a dynamic subdomain redirect without having to configure each individual subdomain? Specifically, what I'm looking to do is redirect any subdomain on my domain to default.php?siteid=SUBDOMAIN. E.g.: site1.mysite.com would redirect to www.mysite.com/default.php?siteid=site1 site2.mysite.com would redirect to www.mysite.com/default.php?siteid=site2 site5678.mysite.com would redirect to www.mysite.com/default.php?siteid=site5678 ... and so on. I know I can easily set up subdomains and redirects via cPanel, but I'd like to not have to do this for every single subdomain, and I would also like it to be dynamic so that it redirects properly regardless of the "subdomain" that's accessed. Is there a way to do this just using .htaccess, or does it also involve a DNS change? Thanks in advance for any help y'all can provide. Quote
TCH-Bruce Posted October 27, 2007 Posted October 27, 2007 Welcome to the forums kmzacks Sorry, I don't know of a way but someone may. Quote
click Posted October 27, 2007 Posted October 27, 2007 I think this would require at least a wildcard record in DNS and probably Apache. The help desk should be able to tell you for sure if it's doable. Once you get the addresses resolving to your site, the redirects can be done using a RewriteRule in .htaccess. Quote
TCH-Carl Posted October 28, 2007 Posted October 28, 2007 We do not allow wild card DNS on our servers, sorry. Quote
dave_st24 Posted October 29, 2007 Posted October 29, 2007 I've created a similar thing for a project on a TCH server, we call the system 'clone sites'. Now we have a folder in the root called 'clone sites' in which we include all files that are needed by the subdomains, then we place a single file called index.php in the subdomain folder, and use .htaccess to rewrite to the clone sites folder. Try this: .htaccess file Options +FollowSymlinksRewriteEngine On RewriteRule ^(.*).php$ index.php?page=$1 [nc,L] index.php <?phpIf (Empty($_GET['page'])) include('../clonewebsites/index.php'); Else include('../cloneWebsites/' . $_GET['page'] . '.php'); ?> This should do the same job. Regards Dave Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.