View Full Version : Website in a subdirectory
jweberg
02-06-2009, 05:06 AM
My primary domain points to /public_html but I would like it to point to /public_html/domain
How do I accomplish this?
I am running a couple of sites and this will help keep things more organized. Thanks.
Early Out
02-06-2009, 08:21 AM
From the knowledgebase: http://helpdesk.bluehost.com/kb/index.php?x=&mod_id=2&id=394
Bob Barr
02-06-2009, 12:28 PM
From the knowledgebase: http://helpdesk.bluehost.com/kb/index.php?x=&mod_id=2&id=394
Thanks for the link. I just tried doing this and keep coming up with an 'Internal Error' page. Here is the code that I added to the .htaccess file in public_html:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?glorydayssportspub.com$
RewriteCond %{REQUEST_URI} !^/glorydays/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$/glorydays/$1
RewriteCond %{HTTP_HOST} ^(www.)?glorydayssportspub.com$
RewriteRule ^(/)?$glorydays/index.html[L]
As far as I can tell, this code duplicates the lines from the knowledge base article. Am I misreading something?
<added>
I just noticed that I had omitted the space between 'index.html' and the '[L]' in the last RewriteRule line. I've changed that but it didn't resolve the problem.
</added>
Early Out
02-06-2009, 12:36 PM
See if this thread, particularly the second-to-last post, provides any help.
http://www.bluehostforums.com/showthread.php?t=12798
Personally, I find it easier just to stick with the default scheme. Everything else looks like a whole lot of thrashing around to accomplish very little.
Bob Barr
02-06-2009, 01:10 PM
I worked my way through the problem. Here is the final code that does work:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?glorydayssportspub\.com$
RewriteCond %{REQUEST_URI} !^/glorydays/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /glorydays/$1
RewriteCond %{HTTP_HOST} ^(www\.)?glorydayssportspub\.com$
RewriteRule ^(/)?$ glorydays/index.html [L]
There are two minor, but very important points:
1. Any RewriteCond line which contains periods needs the backslash escape character immediately ahead of the period. (This isn't shown in the knowlegebase article.)
2. While RewriteRule lines don't require escaping periods, there must be a space between the $ character and the second term of the rule. (This is unclear in the knowledgebase article. It's hard to tell if there should be a space there or not.)
<added>
On further testing, I just realized that this code isn't working either, the site in public_html is still being accessed.
</added>
wysiwyg
02-07-2009, 07:21 AM
http://bluehostforum.com/showthread.php?t=15643
Bob Barr
02-18-2009, 05:35 PM
Well, it took a bit to get it working but I managed to fix up the Bluehost example .htaccess code to get my site accessing correctly in a subfolder.
The changes that I made to the Bluehost code are marked below:
# no change to this line
RewriteEngine on
# added the \ escape character before both periods
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
# added $ character to terminate the folder name
RewriteCond %{REQUEST_URI} !^/mydomain/$
# no changes to these two lines
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# ensured that there was a space between the $ and / characters
RewriteRule ^(.*)$ /mydomain/$1
#added the \ escape character before both periods
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
# ensured that there was a space between the $ and / characters
RewriteRule ^(/)?$ mydomain/index.html
From all indications, my site is now being accessed correctly from the subfolder where I have relocated it.
wysiwyg
02-18-2009, 06:33 PM
You have this twice
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
I'll explain what your code does for you..
# enable rewrites
# this is only required once in an htaccess file
# but must be called before any rewrite lines
RewriteEngine on
# only continue if the domain being accessed is mydomain.com
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
# only continue if the requested directory is not *exactly* /mydomain/
# the purpose of this line is to prevent mydomain.com/mydomain/etc from redirecting
# the $ should actually be left off the end of this
# however, the next two conditions make this one obsolete
#RewriteCond %{REQUEST_URI} !^/mydomain/
# these two lines mean that if the path being accessed exists,
# then the redirect will not continue
# assert that the file being accessed does not exist
RewriteCond %{REQUEST_FILENAME} !-f
# assert that the directory being accessed does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# redirect (literally) everything to /mydomain/(everything)
# the L flag means that this rewrite is over, anything that
# comes after will not have the same conditions as above
RewriteRule ^(.*)$ /mydomain/$1 [L]
# this is redundant, the above rule covers everything
# it says redirect mydomain.com and mydomain.com/ to your new folder
#RewriteRule ^(/)?$ /mydomain/index.html
Required reading
Apache Docs (http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html)
Regular Expressions (http://www.regular-expressions.info/)
Bob Barr
02-18-2009, 06:43 PM
Thank you for the detailed explanation. I had copied the seven active lines directly from the Bluehost knowledgebase article linked above. I'll make the changes that you've noted. Thanks again.
Engineerly
03-30-2009, 01:58 PM
From reading this, it is still not clear exactly what code works.
Extracting only the executable code from wysiwyg's generous explanation, is this the essential code that should be in the Bluehost Knowledgebase?
########################################
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mydomain/$1 [L]
########################################
Thanks,
Ron
felgall
03-30-2009, 02:21 PM
From reading this, it is still not clear exactly what code works.
Extracting only the executable code from wysiwyg's generous explanation, is this the essential code that should be in the Bluehost Knowledgebase?
Yes.
The second line identifies the domain to be redirected and the last line identifies the name of the folder to redirect it into.
The two lines in between tell it not to redirect to the sub-folder if the file or folder being referenced is found in the public_html folder so if you don't want that to happen you can leave those two lines out.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.