Thursday, June 23, 2011

Point Domain to Subfolder in Bluehost for a Joomla 1.6 Installation

Introduction


Bluehost points your primary domain always to the public_html folder.
If you want to install your CMS like Joomla or Wordpress in a subfolder, rather than have all the files in the root, there is no easy build in way at Bluehost.

After reading through the Internet a trying tons of suggestions I found the solution that works for me and a Joomla 1.6 installation. It is a combination of several snippets I found online.

The Solution


Find the .htaccess file in the root folder (public_html) of you Bluehost webspace.
Open the file and add following code. Make sure you read the comments and make the according adjustments.

# Activate the rewrite engine
RewriteEngine on

# Replace yourdomain.com with your domain name.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$

# Replace 'subfolder' with your subfolder name.
RewriteCond %{REQUEST_URI} !^/subfolder/

# Don't touch this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Replace 'subfolder' with your subfolder name.
RewriteRule ^(.*)$ /subfolder/$1

# Replace yourdomain.com with your domain name.
# Replace 'subfolder' with your subfolder name.
# set index.php to whatever necessary for your CMS, for Joomla you don't need to change it
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]

Permanent Redirect yourdomain.com to www.yourdomain.com


If you want additionally forward yourdomain.com to www.yourdomain.com add following code to the .htaccess right below "RewriteEngine On".

# use "www", replace yourdomain with your domain name
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

Permanent Redirect www.yourdomain.com to yourdomain.com


If you instead want to do the redirect the other way around, add following code to the .htaccess right below "RewriteEngine On".

# use "www", replace yourdomain with your domain name
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

Troubleshooting

Please test after every step if everything is working so that you know at which point the new settings broke everything.

It also helps to clear the cache on your browser to make sure the current rewrite rules are used.

If you still have problems with your Joomla, I read it helps to additionally set the live_site parameter in the configuration.php to yourdomain.com.

0 comments:

Post a Comment