+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Redirect Root Directory

  1. #1
    Join Date
    Mar 2006
    Location
    Florida
    Posts
    1

    Default Redirect Root Directory to a Subdirectory

    After searching through the forums, it would appear that there are several people looking to redirect their root directory to a subdirectory, ie. from /public_html/ to /public_html/folder/ so that your site displays www.domain.com instead of www.domain.com/folder in your browser.

    After googling, I found another solution, then I tested on my site, and it works.

    This is what I put in my .htaccess file in /public_html/
    Code:
    # Turn on rewrites.
    RewriteEngine on
    
    # Only apply to URLs on this domain
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
    
    # Only apply to URLs that aren't already under folder.
    RewriteCond %{REQUEST_URI} !^/folder/
    
    # Don't apply to URLs that go to existing files or folders.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Rewrite all those to insert /folder.
    RewriteRule ^(.*)$ /folder/$1
    
    # Also redirect the root folder.
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
    RewriteRule ^(/)?$ folder/index.php [L]
    I created a directory in /public_html/ called folder, so when viewing your files, it looks like /public_html/folder/. Of course you can change the name to whatever you want.

    You need to edit the above code with your information. Rename all the "domain.com" in the code to yourdomain.whatever. You'll also need to rename the "folder" in the code to the name of the directory/folder that you created to house your root directory.

    You'll also need to change the index extension in the last line of code to correspond with your site, like .html or .php and so on.
    Code:
    RewriteRule ^(/)?$ folder/index.php [L]
    or
    Code:
    RewriteRule ^(/)?$ folder/index.html [L]
    If you leave the deafult error pages in /public_html/ they will still work. I also left robots.txt in /public_html/. You can also leave your favicon.ico in /public_html/ and it will work as well.

    Hope this helps. Let me know.
    Last edited by chaos2271; 03-16-2006 at 06:31 PM. Reason: title change

  2. #2
    Join Date
    Feb 2006
    Location
    North of Boston, MA
    Posts
    1,471

    Thumbs up Good stuff!

    Hey, that's good stuff, chaos2271 - nice job on your first post!
    redsox9 - Go Red Sox!!! 2004 and 2007 World Series Champions!
    Visit FenwayFanatics.com, home to Boston Red Sox baseball fans everywhere

  3. #3
    Join Date
    May 2006
    Posts
    11

    Default

    Hi,

    I am completely new in this and will need your help to guide me step by step.

    My shopping cart is currently at http://www.mydomain.com/store/

    I want it to be accessible when users click on http://www.mydomain.com/ (this is the main domain, NOT addon).

    I tried to do a redirect (using CPanel) and every other addon domain gets redirected to http://www.mydomain.com/store/ but I only want my main root domain http://www.mydomain.com/ to redirect to http://www.mydomain.com/store/

    Anyone can help me? Thanks.

  4. #4
    Join Date
    May 2006
    Posts
    11

    Default

    Hi, just to let you know I tried the above solution and it's the only solution that works for me so far. Thanks!

  5. #5
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    75

    Default

    Could somebody help me out with the above redirect please? Unfortunately when I signed up I used my daughters domain which is the main - to keep it tidy I have moved all her stuff into *gina* placed the above redirect in .htaccess (see below)

    problem is when you type shisuta.net it comes with a 404, to get around this I placed a normal redirect
    RedirectMatch permanent ^/$ http://shisuta.net/default.htm
    which forces it to work BUT it also overrides the code below and sends all other errors from the addon domains to that url as well! idea's please?
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?shisuta.net$
    RewriteCond %{REQUEST_URI} !^/gina/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /gina/$1
    RewriteCond %{HTTP_HOST} ^(www.)?shisuta.net$
    RewriteRule ^(/)?$ gina/default.htm[L]

  6. #6
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    1,349

    Default

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^(www.)?shisuta.net [nc]
    rewriterule ^(.*)$ http://shisuta.net/gina/$1 [nc]

  7. #7
    Join Date
    May 2006
    Location
    Maryland
    Posts
    192

    Default

    RewriteRule ^(/)?$ gina/default.htm[L]
    Not sure, but think the problem is that you don't have a space before [L].
    The [L] means this is the last test--if it matches then stop testing.
    The [nc], which Basil recommended, means no case--ignore case.
    Either way, you need a space.

  8. #8
    Join Date
    May 2006
    Location
    Florida
    Posts
    491

    Default

    yah I have the same problem. I hate installing stuff in my root because then it is a pain in the ass to delete. I may start using this. I hate installing something masive in my root then delete it.
    Hanged up my userbar

  9. #9
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    75

    Default

    Quote Originally Posted by KenJackson
    Not sure, but think the problem is that you don't have a space before [L].
    The [L] means this is the last test--if it matches then stop testing.
    The [nc], which Basil recommended, means no case--ignore case.
    Either way, you need a space.

    *nods* thank you sooo much, the space did the trick! Lord, the amount of things I tried and played with and that 'space' did NOT jump at me, thanks for the lesson too I was trying to find what the [L] and [nc] meant.

    Now I can take a breath and stop worrying that she will delete one of my domains by accident.

  10. #10
    Join Date
    Jul 2008
    Posts
    12

    Default

    Thanks a lot i was looking for this information since a long time

+ Reply to Thread

Similar Threads

  1. Changing root to become a sub folder
    By timberford in forum General Questions
    Replies: 13
    Last Post: 02-22-2007, 02:52 PM
  2. server root path
    By memo06dic in forum General Questions
    Replies: 4
    Last Post: 12-30-2006, 07:33 PM
  3. how to redirect?
    By Sai in forum General Questions
    Replies: 10
    Last Post: 03-29-2006, 12:46 AM
  4. 301 redirect does not work
    By motorsport in forum General Questions
    Replies: 1
    Last Post: 03-26-2006, 11:54 AM
  5. Directory Structure for base site.
    By Ducati in forum General Questions
    Replies: 5
    Last Post: 02-24-2006, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts