Last updated October 11, 2015. Created on April 7, 2007.
Edited by rhm5000, Rishi Kulshreshtha, orange-wedge, Willynux. Log in to edit this page.
There are two methods for setting up Drupal 5.x/6.x with Apache on Ubuntu. The first (preferred) method edits the virtual host configuration, which is the default setup on Ubuntu (even for a single-site web server). The second edits the main apache2.conf, which is typical for an older setup.
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:
sudo apache2ctl -M
and seeing if rewrite_module 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/000-default.conf; 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, use sudo nano /etc/apache2/sites-available/mysite-example.conf.
Look for the Directory section referring to the folder where your Drupal site lives found in the /etc/apache2/sites-available/000-default.conf file, typically the line <Directory /var/www>, and also 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. See https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles for more information.
Save this file and then reload Apache with 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.
Below is an excerpt of a virtual host configuration file that would support the last two lines in the above example. This excerpt is not intended to be a complete configuration file, but it is here to provide guidance for your development environment.
<VirtualHost *>
DocumentRoot "/www/Dr6"
ServerName example
ServerAlias *.dr6.example
<Directory "/www/Dr6">
AllowOverride All
</Directory>Edit your config file to suit your development needs, save it; then make sure your site is enabled and finally reload Apache.
Step 1 - Method B: apache2.conf
In Apache version 2, httpd.conf has been deprecated and the new file location is /etc/apache2/apache2.conf.
Thus, the following modification of httpd.conf is no longer necessary to enable the rewrite module (mod_rewrite):
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.cSimply run the following from the terminal: sudo a2enmod rewrite.
To disable the module run: sudo a2dismod rewrite. Remember that this would cause Clean URLs to fail.
Once mod_rewrite is enabled, open apache2.conf in a text editor. The apache2.conf 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:
<Directory /var/www/your_drupal_site>
AllowOverride All
</Directory>After you edit apache2.conf as listed above, you need to reload the server with 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:
<Directory /var/www/your_drupal_site>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>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.
Debugging Rewrite Issues
If you are having problems with getting your rewrite to work you can set Apache to log rewrite errors. To do that add this to the end of /etc/apache2/apache2.conf:
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3Level 0 does no logging. Level 9 logs everything. Choose the level necessary for resolving your issue.
Security Warning: Make sure to either remove or comment the logging code out when finished, or else put the log file in a directory that can't be read by normal users (such as /var/log/apache2). If this is not done, it can result in a security breach. Keep in mind that enabling rewrite logging adds somewhat to server load, and can easily generate large amounts of output not needed on a production server.
Step 2: Enable Clean URLs
Now go to http://yoursite.com/?q=?q=admin/config/search/clean-urls, and run the test for "Clean URLs" (In Drupal 4.6 - 5.x this is buried in the paragraph explaining what "clean urls" are).
Then, select the radio button to set clean URLs to "enabled" and submit the form. You should now be able to access your site using URLs without the query string in them.
Note: In Drupal 7.2, if still you are having issues with Clean URLs, and your site is in maintenance mode, turn off maintenance mode while enabling clean URLs.
Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.
Comments
solution for ubuntu gutsy
Here is what I did to have clean urls with ubuntu gutsy:
a2enmod rewrite
and then added the following lines before line:
<Directory /var/www/>in '/etc/apache2/sites-available/default':
<Directory /var/www/drupal>AllowOverride all
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+\..+)$ [NC]
RewriteCond %{HTTP_HOST} !^.+\..+\..+$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
</Directory>
ADVICE: I'm having problems with apache dir mod using this configuration since now index.php has priority over index.html.
Hope to solve it soon
rewrite.conf file did not exist
In trying to puzzle out why this wasn't working for me on Ubuntu Server 7.10, I discovered that the file /etc/apache2/modules-available/rewrite.load was there but the file /etc/apache2/modules-available/rewrite.conf did not exist. I could use the command 'sudo a2enmod rewrite' and the rewrite mod would 'look' enabled, but clean-urls would still not function because there was no .conf file for the rewrite mod.
I created one with nano, added the text...
RewriteEngine On
...to it, and saved it to /etc/apache2/modules-available/rewrite.conf.
Then, I went to /etc/apache2/sites/sites-available/default and changed both the 'Directory /' and 'Directory /var/www/' AllowOverride values from 'None' to 'All', used a2enmod to enable the rewrite mod, restarted Apache2, and I was then able to turn on Clean URLs in my Drupal install.
Cannot get it to enable in Ubuntu 8.10
I'm running Ubuntu 8.10 on Virtual box and use Drupal 6.10. I followed the directions from all posts but I couldn't enable clear URLs.
1) Ran sudo a2enmod rewrite. Module now found in mods-enabled directory. Also, the mod shows when I run apache2ctl -M
2) Updated .../sites-enabled/000-default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ubuntusrv
ServerAlias ubuntusrv
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
RewriteEngine on
RewriteBase /
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
3) Created rewrite.conf file in ../mods-available as stated in previous comment.
I'm out of ideas on how to get clean url to enable. The radio button is still greyed out.
Assistance will be appreciated :) Thanks
UPDATE:
Err, got it to work finally. Modified as follows:
<Directory /var/www/><IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Thank you!
Every now and then until now I try to get this working and fail. This actually worked! Thank you
PHP
I inherited an Ubuntu box with PHP installed but missing the rewrite.conf (as noted above) and also the line:
AddType application/x-httpd-php .php3 .phpwhich I added to httpd.conf. Without it, apache wouldn't interpret php files as php files.
Ubuntu 8.04 - Apache2
Method #2 works perfectly!
Here's a little visual helper from my /etc/apache2/apache2.conf file, notice the added line:
snippet start...
# The internationalized error documents require mod_alias, mod_include
# and mod_negotiation. To activate them, uncomment the following 30 lines.
# Alias /error/ "/usr/share/apache2/error/"
#
#
# AllowOverride None
# Options IncludesNoExec
# AddOutputFilter Includes html
# AddHandler type-map var
# Order allow,deny
# Allow from all
# LanguagePriority en cs de es fr it nl sv pt-br ro
# ForceLanguagePriority Prefer Fallback
#
<Directory /var/www/drupal_website_install>AllowOverride all
</Directory>
#
# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
# ErrorDocument 410 /error/HTTP_GONE.html.var
# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
# ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.
# Include generic snippets of statements
Include /etc/apache2/conf.d/
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/
...snippet end.
Enable rewrite in Kubuntu 9.10 Karmic Koala
I resolved my problam with the configurantion bellow:
Acess in terminal code line: /etc/apache2/sites-available$ sudo nano default
And write this in to default file.
<Directory /var/www/drupal>AllowOverride all
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+\..+)$ [NC]
RewriteCond %{HTTP_HOST} !^.+\..+\..+$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
</Directory>
Best Regards,
Tks
Finally got it to work.
Hello, I'm running Ubuntu 10.4 and installed the "drupal" package from the Synaptic package manager. I couldn't figure out how to get clean urls working after going through the instructions above.
You really only need to do 2 things and restart. (Also, remember to undo all the other changes that did not work!). I will say "Problems with rewrite" lines above did help show I was rewriting incorrectly but at least I was rewriting!
Step 1:
# Enable the rewrite module
phecht@phecht-desktop:/etc/apache2$ sudo a2enmod rewrite
[sudo] password for phecht:
Module rewrite already enabled
Step 2:
Edit the
/etc/drupal/6/apache.confand add the emphasis lines below.Alias /drupal6 /usr/share/drupal6
<Directory /usr/share/drupal6/>
Options +FollowSymLinks
AllowOverride All
order allow,deny
allow from all
#Attempt to get clean urls for Drupal. Failed.
RewriteEngine on
RewriteBase /drupal6
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
Restart:
Restart the server via:
sudo /etc/init.d/apache2 restart
Still having trouble
I have basically tried all of these with no success. I made the conf file for rewrite, tried adding the module checks in the site conf file but nothing is working.
Here is the relevant part apache2 sites conf file for the site
<VirtualHost *:80>DocumentRoot /var/www/mywebsite.com/htdocs
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/mywebsite.com/htdocs>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
It's ubuntu server 9.10 if that matters and there are several virtual sites on the server and I've gotten clean urls to work on a simpler setup by just putting this code in the apache2.conf file. But when I tried the same thing for this site and server by changing the directory path it didn't work.
<Directory /var/www/>RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
So I'm officially lost, anyone have any ideas?
RewriteBase might be the issue
Hello,
It looks like your RewriteBase is set to "/". Try setting it to /mywebsite.com/htdocs based on what you posted. I have had that problem as well. If that doesn't work try to log the rewrite to a log as specified in the main area above.
This is one of the most frustrating things about Drupal. Not the only one, just the most!!!
Pete
Reply to comment RewriteBase might be the issue
Yes I just had that issue. Am in process of installing D7 multisite on Ununtu localhost. I pasted Option 3 in to the virtual host conf file (took me a while to figure out I had to to use /etc/apache2/sites-available/default), and set the directory to /var/www/drupal7. I also had to set the RewriteBase to /drupal7 as follows:
RewriteEngine On
RewriteBase /drupal7
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Thought I'd mention it because I had to glean these file settings from two different web pages.
apache centos clean url virtualhost server
i actually followed this and it worked for me. http://dev.antoinesolutions.com/apache-server/mod_rewrite
I had the same problem with
I had the same problem with the drupal6 package of ubuntu lucid. The solution I used is here:
https://bugs.launchpad.net/ubuntu/+source/drupal6/+bug/371187?comments=all
Thanks
Thanks for the solution
Multisite via Virtual Hosts
My main drupal install lives in /var/www/html/main and I am trying to get my multisite working but I keep getting this error when trying to access the new site:
<strong>Forbidden</strong>
You don't have permission to access /main/site/test3/ on this server.
Apache/2.2.3 (Red Hat) Server at localhost Port 80
The crazy thing is, if I move drupal into the root dir (eg /var/www/html/) everything works just fine.
Found lots of tutorials but not seem to work for me.
Thank you.
C
This worked for me
I was actually trying to fix a permalink in Wordpress and tried everything in my .htaccess and apache config. Then came across this post. As soon as I enabled mod_rewrite everything worked fine.
Thanks
Simon
Thank you
I almost hit my head against the wall after trying every single method on the internet. Method B did it for me.
I appreciate that. Thanks
Ubuntu 13.10 apache2
For Ubuntu 13.10 I was able to get this done only after doing the folowing :
1.
sudo a2enmod rewrite2.changing the Directory section referring to the folder where your Drupal site lives ,in
/etc/apache2/apache2.conf, and there<Directory /var/www>), and changed the line:AllowOverride None to AllowOverride All
3. Then
sudo service apache2 restartin terminalWorks on 13.10
Thanks for the info... Followed the three steps, did not work... checked my /var/www/drupal-folder, the .htaccess file was not present. Seems the sudo cp -r command did not copy hidden files...
Once I copied the hidden files, including .htaccess, clean urls started working...
Drupal 8 on Ubuntu Server 14.04 (Trusty Tahr)
Drupal 8 on Ubuntu Server 14.04 LTS is slightly confusing. There is no message in Drupal 8 about clean urls not being enabled. You get the main index page after installation but none of the menus work and it looks like your site is broken. I just wanted to note this for anyone googling. Better details are above. To fix I followed similar steps as noted above:
enable clean urls from the command line:
sudo a2enmod rewriteedit the apache config file for your web server's directory to allow overide
sudo vim /etc/apache2/apache2.confAdd this line or change the line in the security model section for your web server. The default is "AllowOveride None"
<Directory /my/root_web_directory/public>Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
restart apache
sudo /etc/init.d/apache2 restartHey guys
there is not much requirement of many changes in .config files, i recomend to verify .htaaccess file and make sure the right Rewritebase is commented out
https://www.drupal.org/node/256410
follow this link. and it solves many issues,
and also make aure your apache has sufficient access to file .htaaccess
for example make sure www-data is the group of .htaaccess.
if at all any changes in config its recomended to create seperate drupal.config file and place it in /etc/apache2/mods-enabled/ directory .. the file includes the following line
Alias /drupal7 /usr/share/drupal7
<Directory /usr/share/drupal7/>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+\..+)$ [NC]
RewriteCond %{HTTP_HOST} !^.+\..+\..+$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
</IfModule>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
This is the way ubuntu instalation of drupal works and the clean url works fine after this
For Apache2 on Ubuntu 14.04,
For Apache2 on Ubuntu 14.04, the Virtual Host "AllowOverride All" setting is located in /etc/apache2/apache2.conf and not in /etc/apache2/sites-available/default.
You will need to find and modify the section of /etc/apache2/apache2.conf from
<Directory /var/www/>Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Thanks tharam04, this works
Thanks tharam04, this works for me.
Clean url Drupal 7 template
Setup: Mac Pro Early 2008, WM ware virtual machine Runs LAMP. Drupal 7 template was working just home page, other pages showed mistake. Fixed by editing etc/apache2/sites available/000-default.conf file. Added at the end:
AllowOverride all
RewriteEngine on
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+\..+)$ [NC]
RewriteCond %{HTTP_HOST} !^.+\..+\..+$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteRule ^files/(.*)$ sites/%1/files/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I use Linode and my example.com.conf is:
Please see here https://www.drupal.org/node/1781930
OR please confirm that this settings is correct?
I use Linode and my example.com.conf is:
# domain: example.com
# public: /var/www/example.com/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster@example.com
ServerName www.example.com
ServerAlias example.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
# Log file locations
LogLevel warn
ErrorLog /var/www/example.com/log/error.log
CustomLog /var/www/example.com/log/access.log combined
</VirtualHost>