In this Rackspace Recipe we’ll configure a ‘sites-available’ file in Apache2 in order to allow Drupal (or WordPress) to rewrite paths. After installing a Drupal site on a Rackspace Cloud server for theĀ first time, chances are you’ll notice it is not possible to enable the Clean URLs feature. This is most likely because Drupal doesn’t have permission to rewrite the path.
Fortunately, this is a very simple issue to correct. In order to gain access to the sites-available file for the site in question, it is necessary to log in via SSH or shell access on a Unix, Linux or a Mac. You can also access the shell by logging into the Rackspace cloud management console for your account. If you are trying to access SSH via a PC I recommend PuTTY.
Each site we publish on our Rackspace server uses a unique sites-available configuration file. These ‘files’ are located in a specific location by default: /etc/apache2/sites-available. Once logged into the server, type the following:
sudo nano yoursitename (enter)
Once you’ve opened the specific site configuration file add the following:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-fsu
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
Of course, change the directory from ‘example’ to the actual directory for the specific site in question. Once this is complete use control-x to exit nano and be sure to save the file under the same name. Once out of the site it couldn’t hurt to restart apache with the following command:
In order to determine success, simply log into the Drupal site and check to see if it is now possible to enable clean URL’s. (/admin/settings/clean-urls)
This technique can also be used to make it possible for a WordPress site to create simple paths. However, the code for WordPress is slightly different:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
