Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Alright, so unlike other solutions I only want one subdomain to appear to be added.

Say I wanted example.com/folder/page.php to be displayed as foo.example.com/folder/page.php, how would I go about doing this?

The foo will never change, and it only needs to be for one page.

Various other sites have been unable to provide an answer, thanks in advance.

Edit: Oh, and I also have full DNS records to the domain.

share|improve this question

migrated from stackoverflow.com Jun 28 '11 at 20:39

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

1 Answer 1

You could not at a subdomain via a .htaccess file.

You need to modify the vhost configuration and add one more vhost.

Have a look at the documentation of your webserver how to do this.

EDIT: There is a logical reason behind this (i don't know all webservers and there features, so correct me if i tell something wrong):

Lets look at a typical HTTP request(send by client):

GET /index.php HTTP/1.1
Host: www.example.org

So, we have the following information in this request:

  • the uri: index.php
  • the protocol version we understand: HTTP/1.1
  • the Host (vhost) we want the uri from

On such a request, the webserver does a few lookups:

  1. Host: first the server needs to know in which directory he should look, this is part of the vHost configuration
  2. the uri you are looking for

As the .htaccess file does belongs to a vhost (a.example.org), we have already behind the vhost decision.

share|improve this answer
    
Is there not some sort of solution of setting up that subdomain, and using the .htaccess on it to display the content from the base url (no subdomain)? –  Jake Jun 28 '11 at 20:13
    
@Jake i will edit my comment to provide more information WHY it is not possible –  Thomas Berger Jun 28 '11 at 20:15
    
But surely if it's possible to add wildcard subdomains, by editing DNS records, it is much easier to just add one? For example stackoverflow.com/questions/586129/… ? –  Jake Jun 28 '11 at 20:30
    
@Jake if you look at the top answer: This is done via server alias. Here you need to modify the virtual host config too. And you need to script the "subdomains" in php, there is still no way to do this via .htaccess –  Thomas Berger Jun 28 '11 at 20:37
2  
@Jake Where do you host your site? Check their Control Panel -- any decent CP will allow you to add subdomains to your domain hosting and point it to any folder on your site. In other words -- use your hoster's Control Panel to configure subdomain .. and the rest (URL rewrite) can be done in .htaccess (if mod_rewrite is available). –  LazyOne Jun 28 '11 at 21:28

Your Answer

 
discard

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