Drupal: What If Your Clean URL Test Fails?
By default, Drupal 7 creates URLs that look like this, “/?q=node/4”.
This type of URL can be hard to read, hard to remember and may not be search engine friendly. The solution is to configure Drupal’s clean URLs.
Drupal provides a test so you can see whether your site is ready for clean URLs:
- In your Drupal site’s admin area, go to Configuration > Clean URLs.
- Click the “Run the clean URL test”.
This tutorial will show you what to do if the test fails.
Step #1. Ensure your .htaccess file is available and working
This step assume that you are using an Apache server.
.htaccess is a file on Apache servers which sets important configurations for the directory it lives in and the directories below it.
The .htaccess file, which is included in Drupal core, defaults to clean URLs. So if your clean URLs are not working, first ensure that you have a .htaccess file in your site’s root folder
Note: Since the file name begins with a dot (.) it is hidden on most file managers and it is easy to omit the file when copying files to a new folder.
If your .htaccess file exists, then ensure that it is working by adding a line of gibberish into the file and reloading your web page. It should immediately return a “500 server error”. If an error is returned then the .htaccess file is working. Remove the line of gibberish that you just added.
If your .htaccess file exists, it’s also worth comparing it to the default Drupal .htaccess file. Some hosting companies will use their own version of .htaccess
If your site does not break, then the .htaccess file is not being used and you will not be able to use clean URLs until you either enable it in the httpd.conf file or work with your web host to have it enabled in your httpd.conf file. Sometimes you may be able to do this from the host’s control panel.
The httpd.conf file is another Apache configuration file, but this file is found in the apache/conf directory (Acquia DevDesktop) or the conf/apache directory (MAMP) on your Apache server, not in the Drupal installation files.
Step #2. Check the RewriteBase setting
If clean URLs are still not working, you may need to change the RewriteBase configuration. First, check the DocumentRoot setting in your httpd.conf file:
You are trying to find out if DocumentRoot accurately reflects the location of your site.
If DocumentRoot is set to /var/www/ (i.e., /var/www/index.html is what is displayed when you browse to your site: http://www.example.com/) and your Drupal installation is installed in the subdirectory /var/www/mysite/, then the RewriteBase directive in your .htaccess file should be set to:
RewriteBase /mysite
and that might help. In some configurations, setting
RewriteBase /
will allow clean URLs. By default the RewriteBase directive is commented out. To uncomment the line, remove the leading hash sign (#) from the line.
Step #3. Check $base_url setting
You may need to manually uncomment the $base_url setting in your settings.php file. The settings.php file is found in the sites/default directory in the root of your Drupal installation. There are several examples in the file, one of which should match your configuration.
This problem often occurs if your web host is using FastCGI. Check with your web host as to whether or not FastCGI is implemented on your server.
Step #4. Location of index.php
It may be necessary to make another change to the Drupal .htaccess file on some, but not all servers. Scroll to the bottom of your .htaccess file and locate a line that looks like this:
RewriteRule ^ index.php [L]
You may need to replace index.php with the URL path to your Drupal installation’s index.php file (only the part after the base URL).
For instance, if your site’s home page URL is http://example.com/subdir/, you might need to use /subdir/index.php instead of index.php.
If your site’s home page URL is http://example.com/, you might need to use /index.php instead of index.php.
I had this happen to me recently on a local install. It turned out that the line enabling the mod_rewrite Apache module was commented out in my httpd.conf after a Mac OS X upgrade. Uncommenting the line and restarting Apache locally fixed the problem.
Great tip, thanks Richard
Thank you so much for this article. I spent almost 2 days trying to find a solution to my problem. My issue was to do with the setting in the apache2.conf. AllowOverride should be set to ALL for the server to read the htaccess file.
Options Indexes FollowSymLinks
AllowOverride All
Require all granted