PDA

View Full Version : Redirect Root Directory


chaos2271
03-16-2006, 06:01 PM
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/

# 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.

RewriteRule ^(/)?$ folder/index.php [L]

or

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.

redsox9
03-16-2006, 06:43 PM
Hey, that's good stuff, chaos2271 - nice job on your first post! :cool:

keltong
10-17-2006, 11:51 AM
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.

keltong
10-17-2006, 07:56 PM
Hi, just to let you know I tried the above solution and it's the only solution that works for me so far. Thanks!

dixieau
10-20-2006, 03:31 AM
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]

Basil
10-20-2006, 08:50 AM
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^(www.)?shisuta.net [nc]
rewriterule ^(.*)$ http://shisuta.net/gina/$1 [nc]

KenJackson
10-20-2006, 08:53 AM
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.

aceofspades
10-20-2006, 10:02 AM
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.

dixieau
10-20-2006, 03:42 PM
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.

jenny4
07-22-2008, 11:28 AM
Thanks a lot i was looking for this information since a long time

imkzru
08-20-2008, 12:26 AM
Ok Next question

I have a main domain that has 3 add on domains.
All 4 of these domains have the same issues that needs fixing.

1. Canonicalization issues: I need to redirect the http://domain.com/ to www.domain.com/

2. Duplicate content issues: I need to redirect http://www.domain.com/index.html to http://www.domain.com/

I have to fix this on all 4 sites.
If I have to put the 301 in the /public_html/ folder what would be the best way to correct this? "I have tried add a 301 to the .htaccess file for each domain and it did not work"

so in short

http://www.domain.com/index.html
http://domain.com/index.html
http://domain.com/

needs to point to
http://www.domain.com/

Per Each Domain.
I can get it to work for one domain but when I try to add the "add on domains" it gets screwed.

Any Ideas?