Wildcard DNS in Mihopa - friendly URL on the subdomain field

This is the general discussion for Mihopa Web Hosting. Please post all general discussion, suggestions, and feedback here, provided it involves Mihopa Web Hosting.

Wildcard DNS in Mihopa - friendly URL on the subdomain field

New postby 1337 HaXorz » Fri Jan 16, 2009 10:33 pm

Hi people, I bring in something that might interest other fellow mihopa users! I just discovered this now hope it helps you!

What is Wildcard DNS? It's when you can type in any random subdomain on your site and it will redirect to your root domain site, or that's what it's been doing for now. The advantages of this is that you can actually catch the random subdomain you typed in using PHP's $_SERVER["SERVER_NAME"], and use it in your code, be it to fetch information from MySQL about the username you typed on the URL, be it to show random stuff based on that word, whatever you want. I heard Deviantart uses this, but I'm not into Deviantart (read: I've visited it two or three times in my life and didn't pay attention to URL) so I can't be sure. Anyway, you might search on the internet and it'll give you complicated solutions about going to your dns manager and activating stuff. On Mihopa, it is as simple as creating a subdomain.
How do you do it? Well, log in into your cPanel and run down to Domains. There, you will find the icon Subdomains, go there.
Now it'll show you a screen with your subdomains and a text box to create a new subdomain. Now it's as simple as typing the bullet (*) into the text field and creating the subdomain. Now all's set. Whenever you try to access a subdomain (probably only unexistant domains, didn't check out what happens if you type in a valid domain), it'll redirect to the index of your root domain. And the best, SERVER_NAME will keep the value you typed in the address bar so basically, you can just explode it by dots (.), catch the first value, and use it in your code. You'll need examples, ok. First I'll let you know the source code of my index page, with variables translated for understanding:

Code: Select all
<?php
$access = explode(".", $_SERVER['SERVER_NAME']);

$subdomain = $access[0];

if($subdomain != "stuff")
{
echo "This page should be related to $subdomain";
if($access[1] != "stuff")
{
   echo " but it can also talk about $access[1] if you want";
}
}
?>


Now, check out what it gives you if you try to access it in different ways:

stuff.mihopa.info -> nothing special no? Well what about
frosty.stuff.mihopa.info -> see magic happens?
mike.stuff.mihopa.info -> magic happens here too
Try to type in other names and it'll give you whatever you typed.

That's cool no? Well, you can also access files this way. I don't have any example files to show the dynamic junk because it's kind of late now, and I'm going on vacation yet once more tomorrow. But it'll work with my car webpage:

stuff.mihopa.info/carrinho
abc.stuff.mihopa.info/carrinho
whatever-you-say.stuff.mihopa.info/carrinho
It'll all access the same page but you'll get to dynamize the stuff if you program the page right.

Fun no? Well it doesn't stop there! You can also use multiple subdomain names in there if you want, see the magic that happens here (bet you already thought it would happen by the code I posted):

frosty.mike.stuff.mihopa.info
jose.other-people.stuff.mihopa.info

Well now, I couldn't get a decent redirection through subdomain manager to work, however, if you manage to edit .htaccess and use the correct mod rewrite stuff, you'll be able to, for example, redirect all member.domain.mihopa.info to domain.mihopa.info/showProfile.php, let's say, and use the server data to show the user's profile instead of the index of your page. I'm just not in the mood of checking out .htaccess today, if I could I'd go see it for you people.

Like it? I just hope so! Don't like it? Post about it! I'll be glad to hear from fellow mihopa members.
Don't have Mihopa yet? Would be awesome if you registered here and supported it!

Thanks people! See you later!
Image
User avatar
1337 HaXorz
User
 
Posts: 174
Joined: Thu Apr 13, 2006 10:02 pm
Location: so, wehn i m bilding the guyss and their like j00 teh bo0m goya devron loaf¿

Re: Wildcard DNS in Mihopa - friendly URL on the subdomain field

New postby Frosty » Sun Feb 08, 2009 10:59 am

Thank you for the information. I might use this in the next generation of Mihopa. It would definately be useful.
Frosty
Site Admin
 
Posts: 375
Joined: Sat Nov 20, 2004 3:13 pm
Location: California, United States

Re: Wildcard DNS in Mihopa - friendly URL on the subdomain field

New postby 1337 HaXorz » Wed Feb 11, 2009 2:24 pm

I'm really glad I could be useful, Frosty! :D
Image
User avatar
1337 HaXorz
User
 
Posts: 174
Joined: Thu Apr 13, 2006 10:02 pm
Location: so, wehn i m bilding the guyss and their like j00 teh bo0m goya devron loaf¿

Re: Wildcard DNS in Mihopa - friendly URL on the subdomain field

New postby SamKevin » Tue Mar 02, 2010 7:14 am

This one is better
SamKevin
 
Posts: 1
Joined: Tue Mar 02, 2010 7:11 am


Return to Mihopa Web Hosting

Who is online

Users browsing this forum: No registered users and 1 guest

cron