Having installed Drupal7.14 on a local Ubuntu 12.04 LAMP server,
I found that the Clean URLs page was showing "The clean URL test failed."

Following instructions at Clean URLs

I have enabled mod-rewrite
sudo a2enmod rewrite

I have added

<Directory /usr/share/drupal7>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

to /etc/apache2/httpd.conf
 

And I have restarted apache
sudo service apache2 restart

I still get, "The clean URL test failed."
Help.

Comments

sdramos’s picture

you have to modify the virtualhost in httpd.conf
change this line AllowOverride None to AllowOverride All

sudo nano /etc/apache2/sites-available/default

<Directory /var/www/ >
   AllowOverride None # modify this line to AllowOverride All
</Directory>
AlanQ’s picture

Thank you drupal_cañetano and leon.vandergrient but still no joy.

On Ubuntu, Drupal 7 is installed in /usr/share/drupal7/
/etc/apache2/conf.d/drupal7.conf contains

Alias /drupal7 /usr/share/drupal7

<Directory /usr/share/drupal7/>
	Options +FollowSymLinks
	AllowOverride All
	order allow,deny
	allow from all
</Directory>

which 'redirects' requests so that I see my Drupal index.php page when I point my browser to http://192.168.0.5/drupal7/

In /usr/share/drupal7/ I have the default .htaccess file which includes, among other things

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule "(^|/)\." - [F]
...

In /etc/apache2/mods-enabled/ I have
lrwxrwxrwx 1 root root 30 May 11 21:59 rewrite.load -> ../mods-available/rewrite.load

In /etc/apache2/ there are two configuration files: apache2.conf (default content) and httpd.conf

httpd.conf was originally empty, but now contains:

# Added by alan
# to allow clean URLs in Drupal7
# copied from http://drupal.org/node/15365

#<Directory /var/www/example.com>
<Directory /usr/share/drupal7/>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

<Directory /var/www/>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

And with all that, I still get 'The clean URL test failed.' when I point my browser at http://192.168.0.5/drupal7/#overlay=%3Fq%3Dadmin/config/search/clean-urls

Any other ideas much appreciated.
Thanks, Alan

grient’s picture

Try RewriteBase /drupal7

AlanQ’s picture

Yes! Brilliant!

Adding RewriteBase /drupal7 to .htaccess in /usr/share/drupal7 did the trick.

I followed it with sudo /etc/init.d/apache2 force-reload followed by sudo /etc/init.d/apache2 restart .

Then, when I reloading the clean URLs page, I got a checkbox to 'Enable clean URLs'.

Thank you, Leon.

pjmcghee’s picture

Hello Leon and Alan,

This post really helped me. I have a slightly different setup though and thought I'd share what I did to make clean URLs work in Drupal 7.14., uBUNTU 12.04, Apache 2

I'm on a dedicated server so I added the text


RewriteEngine on
RewriteBase /drupal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

to the httpd.conf file AFTER

enabling the rewrite_module (shared) via the same method
I then followed with the force-reload and apache2 restart commands
I was then able to check use clean URLs in Drupal 7

Leon, it was your suggestion about
RewriteBase /drupal
that was the key for me. my initial info lacked the /drupal part, which is where my install is located. thanks to both of you for a helpful post!

WorkingMatt’s picture

Only had to change AllowOverride to All in the section of /etc/httpd/conf/httpd.conf to get Clean URLs running.
My own Directory (aka DocumentRoot) was /var/www/html which is where I'd installed Drupal, sdramos post used /var/www, that could change for you too depending on where you installed Drupal. The key is to allow .htaccess to be used for the correct directory from within httpd.conf which may need some poking around if you have more complicated directories e.g. sub-sites.

Here's my blog post showing the process I followed and a few things I checked out along the way.

Thanks all especially sdramos for your helpful posts.

grient’s picture

Try changing the value of

AllowOverride from None to All in apache.conf your virtual server (haven't used Apache in a while).

and putting the .htaccess file in the Drupal root directory. If this works, you know that it has to do with your httpd.conf. If it is still not working it has to be something else.

doncheks’s picture

If you are using drupal 7,then there is no need to edit the .htaccess file because clean url is enabled by default.
So here's the trick,if the clean url test fails on drupal 7.You will have to edit the url.
Your url at the clean url page should be;
http://www.your-site.com/?q=admin/config/search/clean-urls

So edit it and change it to;
http://www.your-site.com/admin/config/search/clean-urls

Now you should see the enable clean url button.Enable it and get yourself a cup of coffee.
Hope that does the trick.

See my reply below if you still have issues.Following this method works 99.9% of time.
Cheers.

BazzeFTW’s picture

I've been spending hours on getting the clean urls to work. This did the trick. THANK YOU.

rasinha’s picture

Worked like a charm!
guys guys go ahead with this ..

doncheks’s picture

To follow my solution above,please disable overlay in core modules.That way we ll have the same url.
If you re working on a local server,simply enable apache rewrite module(wamp icon>Apache>Apache modules) and restart Wamp.Then go back and enable clean url.
Cheers

Brightland’s picture

If you re working on a local server,simply enable apache rewrite module(wamp icon>Apache>Apache modules) and restart Wamp.Then go back and enable clean url.

Excellent - yup this works, thanks.

msmitesh’s picture

Thanx sir for your help

codemode01’s picture

Thank you for turning an otherwise complicated procedure into something relatively simple. I owe you one.

Guy Borghouts’s picture

You, sir, saved my life! After so many tricks, this is the one that set my site in motion!

joco_sp’s picture

This worked! :D

n00b_nuggit’s picture

You sir are a scholar and a gentleman. This workaround worked like a charm!

Fakos’s picture

I can't believe it was so simple as removing the ?q= from the url. I wish you a very Merry Christmas doncheks

Gayan Mettananda’s picture

Worked like a charm!

Mamatha Lekkala1234’s picture

This solved my issue... :)

roblog’s picture

Thanks donchecks that was just what I needed!

rmedard’s picture

Thank you guy. I had spend amounts of time to get this to work, but in vain. You rock.

d_f’s picture

I had all of the configs correct, but somehow i overlooked this,. the simplest of settings.

Thanks!

JackRudolf’s picture

For some reason when I change my URL I get a 404 error. Are you sure that there isn't a need to edit the .htaccess file? My file has only one line, and I'm not sure why but I feel as if it may be the cause of the 404 error when I change the URL.

Shashwat Purav’s picture

Worked like charm!! Saved time :)

Skype ID: shashwatpurav8

brett1’s picture

Well I strugled on this and wwas about to post when it came right
here is what I did

FILE: etc/http.conf

<Directory /var/www/>
   RewriteEngine on
   RewriteBase /drupal7
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
FILE: etc/apache2.conf

ServerName drupal7
FILE: etc/apache2/sites-avaliable

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www
	<Directory />
		Options FollowSymLinks
		AllowOverride All                     // this line
FILE:www/mysite/.htacess

RewriteBase /drupal7                       // I think this is wrong
 enable .... rewrite_module (shared)
see above >> SUDO .......???
 

Then restart the server
sudo /etc/init.d/apache2 force-reload
sudo /etc/init.d/apache2 restart

OK IT WAS HERE THAT I REALISED THAT MY SERVER WAS JUST DRUPAL AND NOT DRUPAL7  SO I ADDED
TO ETC/HOSTS

127.0.0.1	drupal7   
127.0.0.1	drupal   // I already had this line
IT SEEMS OBVIOUS NOW BUT THATS WHERE MY MAJOR ISSUE WAS

I THEN GOT SOME ERRORS - but at least there where errors that I could navigate too and fix.
I think I removed the RewriteBase /drupal7 in the htacess in mysite directory

That took a while and in my excitement I forgot the last couple of steps but it really was the HOSTS file that messed me up.

no_longer_active_19’s picture

On CentOs 6.3 where not using .htaccess and using instead mysubname.conf in /etc/httpd/conf.d included in httpd.conf

On login the url directs to /?=admin/config/search/clean-urls and test fails but if change directory in url bar to
/admin/config/search/clean-urls the checkbox appears but when checked it doesn't save checked.

Below is the mysubname.conf which is basically everything in the .htaccess file plus virtualhost directory.

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$">
  Order allow,deny
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php index.html index.htm

# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_environment_initialize() in
# includes/bootstrap.inc for settings that can be changed at runtime.

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_flag magic_quotes_gpc                 off
  php_flag magic_quotes_sybase              off
  php_flag register_globals                 off
  php_flag session.auto_start               off
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_flag mbstring.encoding_translation    off
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  
  RewriteRule "(^|/)\." - [F]

 
  # Pass all requests not referring directly to files in the filesystem to
  # index.php. Clean URLs are handled in drupal_environment_initialize().

<Directory /var/www/html/mysubname.site.net>
RewriteEngine on
RewriteBase /mysubname
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/mysubname/(.*)$
RewriteRule ^(.*)$ /mysubname/index.php?q=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^index.php [L]

</Directory>

  # Rules to correctly serve gzip compressed CSS and JS files.
  # Requires both mod_rewrite and mod_headers to be enabled.
  <IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
#my rules
NameVirtualHost *:80

<VirtualHost *:80>
ServerName site.net
ServerAlias www.site.net
ServerAdmin admin@site.net
DocumentRoot "/var/www/html"
<Directory /var/www/html/www.site.net/>
AllowOverride All
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName mysubname.site.net
ServerAlias www.mysubname.site.net
ServerAdmin admin@mysubname.site.net
VirtualDocumentRoot "/var/www/html/mysubname"
</VirtualHost>

ServerName localhost

<Directory /var/www/html/mysubname>
  AllowOverride All
RewriteBase /mysubname
</Directory>


    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>

roblog’s picture

Well I've just spent about 24 hrs hacking away and tried petty much everything above. Finally I find a solution to modify the index.php rewrite rule in .htaccess as such:

RewriteRule ^(.+)$ /index.php/$1 [NC,L,QSA]

See here for more info:
http://www.andrew-kirkpatrick.com/2012/06/apache-virtualhost-htaccess-is...

no_longer_active_19’s picture

@roblog that code didn't work for me.

Stagger Lee’s picture

I just had this problem at localhost. Despite i had activated Clean URLs yesterday. And it is easy to overlook it, and lose hours on that problem. To skip unnecessary tweaking htaccess/LAMP/XAMPP/Etc, remove "s" from https.

fcaffield2’s picture

I have an Ubuntu Server installation, and I have enabled clean urls following these steps:

http://www.open-craft.com/blog/enabling-clean-urls-drupal-clean-ubuntu

It works perfectly!

kalidasan’s picture

Only these two steps fixed this issue :)

ogomez78’s picture

Correct for Ubuntu 12.04. Thanks.

alexus’s picture

this is how it should be enabled:

$ cat /etc/httpd/conf.d/XXXXX.conf 
<VirtualHost _default_:80>
	ServerName XXXXX
	DocumentRoot /usr/share/drupal7/
	<Directory /usr/share/drupal7/>
		Include conf.d/drupal7-site.htaccess
	</Directory>
</VirtualHost>
$ 

don't forget to

service httpd restart
mahipal46’s picture

methoad works fine for me..

maralefer’s picture

Pego lo agregado a apache2. Funcionó a partir de agregar AllowOverride All

<Directory /var/www/html/drupal8>
   <strong>AllowOverride All</strong>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
sadanand kenganal’s picture

Enable mod-rewrite : sudo a2enmod rewrite

Open the file sudo vi /etc/apache2/sites-available/000-default.conf

Add these lines inside VirtualHost *:80 tag :

<Directory /var/www/your-project-folder>
   AllowOverride All
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

Don't forget to restart apache2. sudo service apache2 restart

namjoo’s picture

for debian work for me below solution

I edit /etc/apache2/sites-available/000-default.conf
and insert

<Directory /var/www/html/ >
   AllowOverride All
</Directory>

between <VirtualHost *:80> and </VirtualHost>

then run
/etc/init.d/apache2 reload
and last run
/etc/init.d/apache2 restart

Anisorf’s picture

Hi Namjoo,

Thanks a lot, for me these was the only thing that worked.

Anisorf

mondavie’s picture

I am using a shared hosting and a CPANEL. Where do I edit the clean URL? I have disabled the overlay module too but still the test fails.

agenciaq1’s picture

Hi,

If you deactivate your Clean URL configuration and try to set back the Clean URL you will get this error if your site is on Maintenance Mode.
Put the site in live mode and set up the Clean URL again.

Flavio

d_f’s picture

[redacted]