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