When someone wants to run Drupal from a "subfolder" instead of the root (public_html), it's easy to set it up using cPanel for "Add-on" domains. But people face issues running the primary domain from a subfolder. First issue is how to set it up so that the site is pointed at the correct subfolder. Second issue it how to make sure that the "clean URL" functions normally.
Here are steps to follow if you want to load "http://www.mysite.com" from "http://www.mysite.com/subfolder". If implemented correctly, the end user will never get to see that the site is being loaded from a subfolder.
Step 1: Edit the ".htaccess" file in the root (public_html) by adding the following
<IfModule mod_rewrite.c>
RewriteEngine onRewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^$ subfolder/index.php [L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subfolder%{REQUEST_URI} -f
RewriteRule .* subfolder/$0 [L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* subfolder/index.php?q=$0 [QSA]</IfModule>
NOTE: (1) Replace "mysite.com" with your own domain (2) Replace "subfolder" with what ever you have named your subfolder as. (3) This will also force http://mysite.com to be loaded as http://www.mysite.com
Step 2: Find the settings.php file in "public_html/subfolder/sites/mysite.com" and edit it by un-commenting $base_url. It should read something like below
$base_url = 'http://www.mysite.com'; // NO trailing slash!
That's it. Have fun!
Add new comment