Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an Ubuntu box that I use for all sorts of things. One thing I really want to do is redirect a sub domain to a local script.

For example thisbit.example.com should actually show the content from localhost/~USER/FAKE.thisbit.example.com/ which is a folder that Apache is running for me which contains a very simple PHP script which implements an offline version of a server script that I am testing against.

But example.com should continue to behave normally as should notthisbit.example.com etc.

Ideally I need to be able to switch from testing to live with minimal fuss when the time comes.

share|improve this question

migrated from stackoverflow.com Aug 31 '12 at 21:19

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

    
Have you tried adding a specific entry for "thisbit.example.com" that redirects to localhost and to the specific port Apache is running on? –  Oday Mansour Aug 30 '12 at 13:14

2 Answers 2

Add your domain name and IP address to /etc/hosts file. For example

127.0.0.1 thisbit.example.com

Edit:

Add configure apache to proxy to your fake path

ProxyPass / http://localhost/~USER/FAKE.thisbit.example.com/

ProxyPassReverse / http://localhost/~USER/FAKE.thisbit.example.com/

share|improve this answer
    
I'm going to give this a go. Cheers. (Will mark as accepted when all pans out). –  Matthew Brown Aug 30 '12 at 13:28
    
ProxyPass I take it some sort of mod I need to add to apache? –  Matthew Brown Aug 30 '12 at 15:59
    
Aded ProxyPass and that seems to be working but I'm getting Forbidden from my own Apache server. –  Matthew Brown Aug 30 '12 at 16:10

user637152 put me on the right track with editing /etc/hosts

127.0.0.1 thisbit.example.com

Which had things resolving to the wrong folder. But the modproxy was not working for me at all.

In the end it dawned on me that I had a virtual host incoming. So I set Apache up to deal with that. Now I own the domain for this PC.

<VirtualHost thisbit.example.com:80>
    ServerName thisbit.example.com
    DocumentRoot //home/USER/public_html/FAKE.thisbit.example.com/
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /home/USER/public_html/FAKE.thisbit.example.com/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>    
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.