homepage Welcome to WebmasterWorld Guest from 54.227.171.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / WebmasterWorld / Domain Names
Forum Library, Charter, Moderators: buckworks & webwork

Domain Names Forum

    
Wildcard forward subdomain
Wildcard forward subdomain
pastorvictor



 
Msg#: 4546366 posted 3:24 am on Feb 18, 2013 (gmt 0)

Hello,

I don't know if this is possible, but is there a way for me to add a wildcard to my site's subdomain so that whatever you type is forwarded to the same word after the domain name?

For example, if you type chat.mydomain.com it would take you to mydomain.com/chat

I ask this because I'm getting ready to open a blog site where people will be able to create their own blogs. My software adds their accounts as mydomain.com/username, but I would like for them to be able to enter username.mydomain.com and have it take them to mydomain.com/username

I tried adding the wildcard "*" and then forwarding it to mydomain.com/* but that only takes them to the index of my site.

Can this be done?

Thanks in advance.

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4546366 posted 5:02 am on Feb 18, 2013 (gmt 0)

I don't see why not. But you left out an utterly crucial piece of information. Where is this forwarding to take place? Apache, php script, That Other Server, within the html itself, etc. And, equally important, why isn't your host doing this already as part of the wild-card subdomain package? It isn't enough to have software to create the accounts; you also need the DNS to point people to the right place.

If I treat this as an Apache question-- which it may not be, since you didn't say-- the most obvious option is

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(\w+)\.example\.com
RewriteRule (.*) http://example.com/%1/$1 [R=301,L]

Do not cut and paste. That was off the top of my head. You would also need to exclude names that are already used by regular top-level directories-- /images/ and that kind of thing.

As written, this will result in a 301-to-404 sequence if someone requests a nonexistent subdomain-- or a bogus page within a real subdomain. So option B is something more like

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(\w+)\.example\.com
RewriteRule (.*) http://example.com/fixup.php?subd=%1&req=$1 [L]

letting fixup.php do the work, ending up with either a 301 or a 404.

And then there's a whole nother set of options if you don't want people redirected at all, you're just talking about where the subdomain.example.com content lives. In that case you leave out the [R=301] flag but make a preceding rule that redirects people who asked for example.com/subdomain/ by that name. (People can type anything they like. But they all have to end up at the same URL.)

All of which takes us back to:
I tried adding the wildcard "*" and then forwarding it to mydomain.com/* but that only takes them to the index of my site.

Where, exactly, did you try this?

pastorvictor



 
Msg#: 4546366 posted 5:33 am on Feb 18, 2013 (gmt 0)

Oh man, this is more complex than I thought.

The pages it will go to are Drupal blog pages...I think they're in php. Just regular blog pages.

And I tried to add that where my host allows me to set up subdomain forwarding. They just ask for the subdomain name, so I put an asterisk there, and then they want the subdirectory/URL that it points to, so I wrote /*

So then this needs to be done with Apache?

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4546366 posted 7:54 am on Feb 18, 2013 (gmt 0)

We need more information. For starters: what do you want the user's address bar to end up saying if they start out asking for

mydomain.example.com/some-complicated-page-name
?

In one sense all subdomains are forwarded, because physical directories don't exist in four dimensions. With whatever your host is currently doing, do requests for

subdomain.example.com/
and
subdomain.example.com/pagename
and
subdomain.example.com/directory/pagename

all end up at

example.com/subdomain/
?

Next question is how much other rewriting will be happening. When people say "blog" I hear "cms" and those tend to come with their own htaccess files that you have to work around. I'm sure Drupal does. In fact I'm surprised it doesn't already include a section on subdomains.

And, finally, we need a moderator, because I don't think this is a domain-names question at all. Those questions are about selecting names for the best SEO, and squ-- er, I mean registering potential names-- and the reasons for going with one TLD over another, and the Hyphen Issue, and...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / Domain Names
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved