How to install drupal in a sub-directory
I tried to install a drupal site in a sub-directory of a domain and I ran into some problems. I will explain here how I solved them.
Many forum topics and issues on drupal.org and elsewhere on the web discuss how to install drupal in a sub-directory of your domain and to have it appear as if it were at the root of your domain, e.g.:
– drupal is in www.mydomain.com/sub-dir, but your webserver opens your drupal site when you go to www.mydomain.com.
I — on the other hand — wanted to have it installed in a sub-directory and have it APPEAR in that subdirectory, i.e.:
– drupal is in www.mydomain.com/sub-dir and the webserver opens the drupal site when people go to www.mydomain.com/sub-dir. Thus the top domain could have some very light page with just a few links which redirect the people to different sections of your site which may each be a seprate drupal site or they be implemented with totally different system, eg. one drupal and another one – WP, etc..
The problem when drupal is installed in a sub-directory is that this breaks drupal’s “Clean URL’s” system.
Here’s what you need to do to have druapl work from a sub-directory:
1. Add the following to your .htaccess file:
RewriteBase /sub-dir
Note that this goes into the .htaccess file in the “sub-dir” subdirectory, not your website root-dir htaccess file!
2. You DO NOT need to modify the $base_url setting in your sites/default/settings.php file. Many tutorials and forum topics say that you need to modify your base_url to point to www.mydomain.com/sub-dir but that was not necessary in my case. Just to be as exhaustive as possible – I did try it with the base_url modified and it also worked for me but I then commented it off again since everything worked fine without it.
– – –
If you also want your visitors to be able to access you drupal site via a sub-domain name, that is open the drupal site in the sub-directory when they go to e.g.: shop.mydomain.com, you can achieve this via subdomain-redirection:
Go to the sub-domains section of your cPanel (or whatever your host provides as a tool to manage sub-domains) and redirect the shop.mydomain.com subdomain to “www.mydomain.com/sub-dir”. This way whenever people try to open shop.mydomain.com they will be redirected to your drupal site. Now, mind you the URL in the browser will also be changed to “www.mydomain.com/sub-dir”, so they will not see e.g. shop.mydomain.com/products but “www.mydomain.com/sub-dir/products”. IMHO this is not a big deal – just name your subdirectory the same as the sub-domain you want to use, i.e. in the above example name both the subdoamin and sub-directory “shop”.
3 Responses to How to install drupal in a sub-directory
Leave a Reply Cancel reply
-
Categories
- Android Development
- Bash
- C programming
- dpkg/apt-get
- drupal
- Emacs
- Git
- Java
- Linux administration
- Linux device drivers
- Linux Gaming
- Linux kernel
- Linux Networking
- Linux on Windows
- Linux printing
- Linux sound and ALSA
- Package Managers
- Programming
- RPM
- Shell and environment
- Tips and tricks
- Uncategorized
- VirtualBox
- Virtualization
- web development
- wine
- WMaker
- Wordpress Tips
- X Window System
- XFCE
-
Articles
- August 2020
- August 2019
- May 2019
- July 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- April 2016
- March 2016
- December 2015
- November 2015
- September 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- October 2014
- February 2014
- January 2014
- November 2013
- October 2013
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
-
Meta
Cloud
audio bash boot compile C programming cups drupal emacs etc Fedora git grep how to httpd init kernel libc linux linux partition localtime login make mount mp3 mysql networking oracle package managers password phpMyAdmin programming rpm shell sql vbox version control system virtual box vm web server wordpress www xargs xfce xwin yum
Is the .htaccess the one in the Drupal subdirectory or the main one for the entire website?
… ah yes – good point, thank you 🙂
The .htaccess file where you add the
RewriteBase /sub-dir
command is the one in the subdirectory. In my particular case I dont’t even have a htaccess file in the main site dir.
And a similar problem I just finished banging my head against:
I wanted to move a live drupal site to my localhost for testing. To a sub-directory on my localhost to be exact.
At my hosting provider the site appears at the top-level directory of the domain, i.e. at http://www.example.com.
On my local host the top-level is already used for something else and I did not want to break it so instead I wanted my site to be accessible locally as http://localhost/example
I created the ‘example’ sub-directory in my doc-root, copied my site there, added the database and… it did not work 🙂
Well.. it KINDA worked… it shoed the main page but none of the links worked. After fiddling with drupal’s base_url (in files/default/settings.php) and with RewriteRule and RedirectMatch commands in my .htaccess file I finally solved the problem really easy:
– Simply disable Clean URLs 🙂
I realize that this may not be the best solution for everybody, especially if you need to test some of your clean URL paths but I could not get it working the other way, so there… this works for me.. 🙂
I would of course appreciate any tips on how this could be done without disabling Clean URLs. But I think this is not an easy nor universal task since people (including myself) often have link mappings withing drupal. And sometimes also hardcoded URLs (I dont use these.. learned my lesson long time ago 🙂 ).