Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Some websites have variable prefixes. For example: www.example.com/bob_11 is presented as bob_11.example.com. How do I do that? I assume its a sub-directory, but can't find anything explaining how to treat it as such.

I recently set up an apache server, if the specific server software is a factor. The closest I've found is mod_rewrite, but it clearly doesn't do what I want.

Searching for help on this issue has been tricky, as I'm pretty sure "prefix" is the wrong word for what I'm describing. Aside from how to do it, what's the word for the process I'm describing?

share|improve this question

migrated from stackoverflow.com Oct 9 '12 at 15:55

This question came from our site for professional and enthusiast programmers.

    
I think you need to define this on the server. On Control Panel you should be able to set sun directories –  Mahsa Teimourikia Oct 9 '12 at 14:09
3  
"subdomain" is the word you're looking for there. You'll need to set up that subdomain in your DNS. –  ultranaut Oct 9 '12 at 14:11

4 Answers 4

You are looking to create a subdomain of your website. You would need to define a virtual host on Apache and define a new folder for your new subdomain. You could then use mod_rewrite, or even a redirect to move the user to your subdomain when they hit www.example.com/bob_11.

You will also need DNS entries to make the URL display correctly in visitor's browsers.

share|improve this answer

You're looking at making a subdomain. Many modern hosting providers will over this as part of their backend / control panel, so the exact answer would depend on your hosting provider.

share|improve this answer

What you need is called virtual hosts, here is the link on which you can learn more about it...

http://httpd.apache.org/docs/2.2/vhosts/examples.html

It is best to go to your domain registrant panel and add there subdomain bob_11.example.com pointing with A record to IP address of your server...

Then on the server use command line to find httpd.conf:

Try:

 find / -name httpd.conf
  • most probably you will need root access rights to do find from / dir so put sudo in front of above command. Or login as root before doing it.

And there configure virtual host according to manual on the link above.

Restart apache after saving httpd.conf!

share|improve this answer

There are two issues here. It sounds like you want to create a name based virtual host. You configure a name based virtual host in Apache.

http://httpd.apache.org/docs/current/vhosts/name-based.html

So you would have something like:

NameVirtualHost *:80  (Note NameVirtualHost is deprecated in Apache 2.4 which I've linked above)

<VirtualHost *:80>
ServerName bob_11.example.com
DocumentRoot /www/bob_11
</VirtualHost>

The second issue is how you configure your DNS to recognize the name, or what you have called a prefix. The easiest way is to add a CNAME record which contains the name you want and points to the existing www name as an alias.

Your DNS should be configured like so:

bob_11.example.com.             CNAME   www.example.com.
www.example.com.                 A       192.168.1.2
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.