Clean URLs with Apache 2 on Ubuntu
Step 1 - Method A: "Virtual Host" Setup
First, from the Linux command line, enable the rewrite module for apache with this command:
sudo a2enmod rewrite
You can check to see if this worked by running:
apache2ctl -M
and seeing if it is on the list.
Next, use an editor (such as
nano
) to edit the appropriate Apache configuration file for your Drupal site in the /etc/apache2/sites-available/
directory. For a single site, the file is /etc/apache2/sites-available/default
; if you have multiple sites, the file names should reflect the names of the sites to which they refer. Thus, to edit the default site configuration, usesudo nano /etc/apache2/sites-available/default
Look for the
Directory
section referring to the folder where your Drupal site lives (in /etc/apache2/sites-available/default
, this is typically
), and change the line:AllowOverride None
to AllowOverride All
(This directive permits an .htaccess file, such as Drupal's, to be used to override Apache's default settings, and is necessary to allow the URL rewriting to work. Seehttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles for more information).
Save this file and then reload Apache as follows:
sudo /etc/init.d/apache2 reload
Subdomain Setup
Instead of creating multiple virtual host files, you can create one virtual host file that uses a wildcard in the ServerAlias. Both a simple multi-site Drupal setup and multiple Drupal versions can run this way, if the different subdomains are defined for each site in settings.php.
Consider the following and modify your configuration file to fit your needs.
Here is a partial listing of a virtual host configuration file that would support the last two lines in the above example. Note this is not intended to be a COMPLETE configuration file, but rather provide guidance for your development setup.
DocumentRoot "/www/Dr6"
ServerName example
ServerAlias *.dr6.example
AllowOverride All
Edit & save your config file to suit your development needs. Assuming the site is already enabled, then reload Apache.
Step 1 - Method B: apache2.conf
In Apache version 2, httpd.conf has been deprecated and the new file is located at:
/etc/apache2/apache2.conf
.
Thus, it's no longer necessary to do the following in httpd.conf to enable the rewrite module (mod_rewrite):
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
AddModule mod_rewrite.c
Simply run the following from the Linux command line:
sudo a2enmod rewrite
To disable the module you can run:
(**Note that this would cause clean URLs to break.)
sudo a2dismod rewrite
(**Note that this would cause clean URLs to break.)
Once mod_rewrite is enabled, open apache2.conf in a text editor. Note that it will probably be read-only, so you will need sudo privileges to edit it. Use a command such as:
sudo nano /etc/apache2/apache2.conf
Find where the sections are in your apache2.conf and add another one for your Drupal site similar to this:
AllowOverride All
After you edit apache2.conf as listed above, you need to restart the server by:
sudo /etc/init.d/apache2 reload
Step 1 - Method C: Add Rewrite Rules Directly to Virtual Host or apache2.conf
If you do not wish to allow .htaccess overrides, you can add the rewrite rules directly to a virtual host file or apache2.conf. The following should work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
This can provide slightly faster server performance since Apache will not look in every directory for an .htaccess file.
Note that, for proper security, you will need to add in the rules from the Drupal files directory's .htaccess file as well.
More info >>
http://drupal.org/node/134439
0 comments:
Post a Comment