Drupal paths and Clean URLs

Drupal page requests

Drupal processes most content requests by passing them to the script located at index.php. It sends a query in the request to the server in the form of ?q=[something]. In most cases, the [something] is either a piece of content, such as node/345, or a request for an administrative page, such as admin/build/modules. The following list shows information requested from Drupal and the request sent to the web server:

Desired from Drupal Requested from the web server
node/312 index.php?q=node/312
admin index.php?q=admin
user/1 index.php?q=user/1

Drupal's Clean URLs feature

Early search engines gave lower search rankings to sites that used the ?q= or similar style URLs, considering dynamically generated content to be inferior to static pages. Although the major search engines aren't as picky as they once were, http://example.com/about-us is easier for users to read and remember than http://example.com/index.php?q=about-us or similar.

Full documentation on clean URLs in Drupal is available at Step 6: Configure clean URLs on drupal.org.

If available, Drupal uses the Apache mod_rewrite module to handle requests and convert them from node/312 style requests to index.php?q=node/312. During installation, Drupal runs a test to see if your server is configured to use mod_rewrite and the .htaccess file. If all is well, the installer activates Drupal's Clean URLs feature.

.htaccess file

By default, Drupal's Clean URLs are driven by a file named .htaccess, which is a file that contains a set of rules that tell Apache how to handle requests. The important lines for Clean URLs are near the end of the file:

Drupal 7 and Drupal 8

# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

Drupal 6

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Thee three RewiteCond lines tell the Apache web server that if a request comes in for a file or a directory that doesn't exist in the filesystem, the server should take whatever was requested and put it after the index.php?q= request that is passed to Drupal. This is handled entirely inside the web server, and website visitors never see the index.php?q= version of the request.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
By submitting this form, you accept the Mollom privacy policy.

Contact supportStill need assistance? Contact Acquia Support