Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Fix problems with clean URLs in Drupal

14/04/2025, by Ivan

Basics

In Drupal 8, clean URLs are enabled by default and cannot be disabled. However, the rewrite module must be enabled on your web server.

Check your browser's address bar. Your site URLs should not contain ?q= in the URL.

Example of correct “clean URLs”

http://www.example.com/node/83

Example of non-working “clean URLs”

http://www.example.com/?q=node/83

There are additional setup instructions for clean URLs on various systems like Apache, WAMP, XAMPP, and IIS.

Server Configuration for Clean URLs

You can read more about other web server requirements.

Server Configuration for Clean URLs on a Dedicated Server with httpd.conf

Enabling clean URLs on a dedicated server involves the following steps:

1. Enable mod_rewrite for Apache. You can consult your web host or refer to the Apache mod_rewrite documentation for guidance. At a minimum, you need to ensure mod_rewrite is enabled for your Apache installation.

To check if mod_rewrite is available in Apache2, run the following to list installed modules:

apache2ctl -M

Other variations include:

apachectl -M
httpd -M

2. Check the output for rewrite_module to confirm it is enabled.

If rewrite_module is missing, it must be compiled or loaded as a module. Typically, Apache can be instructed to load it with:

LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c

You may also enable it with:

a2enmod rewrite

Remember to restart Apache for changes to take effect.

3. Locate your Apache config file, which could be httpd.conf, vhost.conf, site-specific config (like “default”), or apache2.conf. Try:

find /etc -name httpd* or find /etc -name apache2*
If you don't have write permissions for these files and clean URLs don't work out-of-the-box, contact your sysadmin or hosting provider. However, you can still inspect these config files to troubleshoot.

4. Copy or include Drupal settings in the config file. Refer to these instructions and the .htaccess file for rules like this:

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

Or this for Debian 8 + Apache2 + ISPConfig with wildcards:


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

Ensure you check the .htaccess for your Drupal version (e.g., 8.x).

Note: If you don’t want rewrite rules in Apache’s config, use Drupal’s .htaccess file and set the AllowOverride directive:

AllowOverride All
AccessFileName .htaccess

Read this article for a .htaccess walkthrough and see Apache's AllowOverride directive examples.

Note about MultiViews: Apache’s MultiViews feature (content negotiation) can interfere with Drupal clean URLs. Avoid using MultiViews unless you're sure it's needed. See Apache docs for MultiViews.

Server Configuration for Clean URLs on Shared Hosting with .htaccess

Drupal’s default .htaccess file should support clean URLs. Be sure you didn’t skip copying it (it starts with a dot). Use ls -a to confirm it’s present.

If it's present but clean URLs still don’t work, try troubleshooting below or contact your host.

Troubleshooting

Check if .htaccess is Used

Apache must be told to respect .htaccess rules. This is off by default but commonly enabled by hosts. The AllowOverride All directive enables .htaccess support.

To test if .htaccess is being read, insert some junk into the file. If the site throws a "500 Server Error", then it is being read. (Remove the junk immediately.)

If the site continues to work, .htaccess is ignored. Contact your host or enable it via httpd.conf.

Setting RewriteBase

The RewriteBase directive might need adjustment. It may be set in .htaccess or httpd.conf depending on where the rewrite rules reside. By default, it is commented out and works for many setups.

If clean URLs fail, you might try setting:

RewriteBase /mysite

If your site is installed at http://example.com/mysite/, this may help. In other cases:

RewriteBase /

might work.

$base_url

You may need to set the $base_url variable in settings.php manually, especially on FastCGI servers. See this PHP bug for more.

Multi-site

RewriteBase works if all sites are served from the same subdirectory. For example,

RewriteBase /

will work for:

http://www.example.com/
http://www.example2.com/
http://www.example3.com/

RewriteBase /mysite

will work for:

http://www.example.com/mysite
http://www.example2.com/mysite
http://www.example3.com/mysite

If your sites are in different subdirectories, RewriteBase won’t work alone. You’ll need rules like:

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

Place this before other rewrite rules.

Location of index.php

Some configurations may require a tweak to the final rewrite rule:

RewriteRule ^ index.php [L]

You may need to replace index.php with a path like /subdir/index.php if your site lives under a subdirectory.

Create Friendly URLs with the Path Module

Using clean URLs lets Drupal generate URLs like "http://www.example.com/node/83". To change "node/##" to something like "news/june-1st-news", enable the Path module. See the Path module documentation for more details.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.