Redirect all requests from the main domain to a subfolder/subdomain of the same site...

Posted on 2006-06-02
Last Modified: 2013-12-24
Hi all,

I have a domain, call it for now. i want to have it so that when anybody goes to it will either redirect to, or ideally it would be awesome if it could still say but if that's not possible i can live with it ;)

so as an example, if the folder structure was something like this...


i would like it so that when you go to it would display the index file above... and if you go to it would display the relevant picture, etc.

If i go to, i would like to be presented with the alternative index file.

I'm told that I need to make a .htaccess file... is this correct? what would i put in it? My hosting package has CPanel 10, if it makes a difference.


Question by:SamShaw
    LVL 29

    Expert Comment

    I usually use IIS but check out this redirect in htaccess:

    You should be able to redirect it to anywhere you want.  Make sure that it is a permanent 302 redirect

    LVL 21

    Expert Comment

    by:Julian Matz

    If you want to redirect with /subfolder in the address bar, you could simply use a .htaccess file:

    # 301 Redirect
    RedirectPermanent /

    ^^ This will do a permanent redirect (status 301).

    If you need to hide /subfolder, you would need to use mod_rewrite, something like this:

    # Rewrite URLS
    Options +FollowSymlinks
    RewriteEngine On
    RewriteRule ^/(.*) /subfolder$1
    LVL 1

    Author Comment

    julianmatz, i have tried your Rewrite exmple, but it doesnt seem to work. at i still get the main webroot directory, not the subfolder one.. i have googled around for Rewrite, but it is all a bit too indepth for me!
    LVL 21

    Expert Comment

    by:Julian Matz
    Hi Sam,

    I'm no expert on rewriting. I can always manage to get what I want, but sometimes it takes a bit of playing around with the rewrite rules.

    When testing, you should always use the [R] flag. The 'R' stands for redirect and it will show you in the addressbar if the rewrite process worked. Once it does, you can simply remove the flag...

    The good thing is that the rewriting in general works on your server, because otherwise you would have probably received a 500 internal server error.

    Here are a couple more to try out:

    RewriteRule ^(.*)$ /subfolder/$1 [R,L]

    RewriteRule (.*) /subfolder/ [R,L]

    RewriteRule ^/$ /subfolder/ [R,L]
    LVL 4

    Accepted Solution

    create a php file as ur main index file and go


    header ("Location: $URL");

    LVL 21

    Assisted Solution

    by:Julian Matz
    Hi John-Bayles,

    That would be the most obvious method, and admitingly I didn't even think of it! :)
    It won't mask the subfolder though...

    If this isn't a problem then I would also suggest adding a 301 header:

    header ("HTTP/1.1 301 Permanently Moved");
    header ("Location: $URL");
    header ("Connection: close);

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Some time ago I was asked to set up a web portal PC to put at our entrance. When customers arrive, they could see a webpage 'promoting' our company. So I tried to set up a windows 7 PC as a kiosk PC.......... I will spare you all the annoyances I…
    #Citrix #Citrix Netscaler #HTTP Compression #Load Balance
    Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now