Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-06-02
8
Medium Priority
?
981 Views
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...

+public_ftp
     +subfolder
          +images
               -image1.jpg
               -image2.jpg
          +scripts
               -script1.js
               -script2.js
          -index.php
          -someotherpage.php
     +othersubfolder
          -index.php

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.

Thanks,.

Sam.
0
Comment
Question by:SamShaw
6 Comments
 
LVL 29

Expert Comment

by:coreybryant
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

-Corey
0
 
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

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteRule
0
 
LVL 1

Author Comment

by:SamShaw
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!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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]
0
 
LVL 4

Accepted Solution

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

<?


$URL="www.yoursite.com/sub/";
header ("Location: $URL");

?>
0
 
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:


<?
$URL="http://www.example.com/subfolder/";
header ("HTTP/1.1 301 Permanently Moved");
header ("Location: $URL");
header ("Connection: close);
exit;
?>
0

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