Learn how to a build a cloud-first strategyRegister Now


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

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

I have a domain, call it www.domain.com.au for now. i want to have it so that when anybody goes to www.domain.com.au it will either redirect to www.domain.com.au/subfolder, or subdomain.domain.com.au... ideally it would be awesome if it could still say www.domain.com... 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 www.domain.com.au it would display the index file above... and if you go to www.domain.com.au/images/image2.jpg it would display the relevant picture, etc.

If i go to othersubfolder.domain.com.au, 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

ID: 16817353
I usually use IIS but check out this redirect in htaccess: http://www.javascriptkit.com/howto/htaccess7.shtml

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
ID: 16817854

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

# 301 Redirect
RedirectPermanent / http://www.domain.com.au/subfolder/

^^ 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


Author Comment

ID: 16821419
julianmatz, i have tried your Rewrite exmple, but it doesnt seem to work. at www.domain.com.au 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!

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 21

Expert Comment

by:Julian Matz
ID: 16821507
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]

Accepted Solution

John-Bayles earned 300 total points
ID: 16821573
create a php file as ur main index file and go


header ("Location: $URL");

LVL 21

Assisted Solution

by:Julian Matz
Julian Matz earned 300 total points
ID: 16821594
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is in regards to the Cisco QSFP-4SFP10G-CU1M cables, which are designed to uplink/downlink 40GB ports to 10GB SFP ports. I recently experienced this and found very little configuration documentation on how these are supposed to be confi…
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
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…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

810 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