How to Fix Drupal “Clean URLs” Not Working

Drupal is an open-source content management system written in PHP. It offers an alternative to other CMSes, being full of features and highly customizable. Drupal enables clean URLs by default since version 9 to allow its users to more easily read the URLs. However, this default setting doesn’t work depending on your server’s configuration. In this article, we will show you how to fix Drupal Clean URLs issues.

What are Clean URLs?

In more recent Drupal versions like 9 and 10, Drupal enables clean URLs by default, and it can’t be disabled. For this feature to work, a rewrite module must be installed on your web server. You can check your Drupal link in your browser’s address bar. Your website’s URLs should not contain ?q= within the URL. For example, you should not see this in your URL bar:

https://yourdomain.com/?q=node/99

It should look like this instead:

https://yourdomain.com/node/99

The clean URLs in Drupal provide several key benefits, such as:

  • More User Friendly, Easier to Read: The links in clean URLs are easy to remember if compared to the links in a long URL with random strings containing numbers and letters.
  • SEO Friendly: The clean URLs might affect your Search Engine Optimization results. Please note that shorter link structure is generally better. Search engines love concise URLs, and using links that contain keywords is another valuable technique to optimize your clean URLs for SEO purposes. By incorporating relevant keywords into your clean URLs, you assist Google in understanding the nature of your website’s content.
  • Easier Link Sharing: Meaningful clean URLs makes it easier to share links. When users share links on various platforms such as social media or emails, descriptive clean URLs offers a glimpse of the content they will be directed to. This enhances the chances of click-throughs since users are aware of the destination they will be going towards.

How to Fix Drupal “Clean URLs” Not Working

There are some steps to complete to solve the issue.

Enable The Rewrite Module for Apache

On Operating Systems like CentOS, AlmaLinux, Rocky Linux, etc., the rewrite module is enabled by default. If you are running Ubuntu, then you will need to enable it manually. First, let’s check the module status.

$ apachectl -M | grep -i rewrite

The command above should return a message, like this:

master@home:~$ sudo apachectl -M | grep -i rewrite
rewrite_module (shared)

If you do not see any message after issuing the command, then you need to execute the command below to enable it.

$ sudo a2enmod rewrite

Once enabled, we can restart the Apache service:

$ sudo systemctl restart apache2

With this module now enabled, try to load your website again. If you still don’t have clean URLs, read on – there’s more you can try.

Check .htaccess File

If Apache rewrite module is enabled and the clean URLs are still not working, check your .htaccess file. Make sure there is a .htaccess file in your website’s document root. If you have it and it’s still not working, make sure you have the correct RewriteBase path in that .htaccess file.

When installing Drupal under a subdirectory, for example: https://yourdomain.com/drupal, then the RewriteBase directive should look like this:

RewriteBase /drupal/

If your Drupal website is installed on the domain’s or subdomain’s document root and not under a subdirectory, then it should look like this.

RewriteBase /

Make sure you comment out the line by removing the # symbol in front of RewriteBase, if any, otherwise this will not work. For example, if the line looks like this:

#RewriteBase /

Then you need to remove the # symbol. It should look like this:

RewriteBase /

Save your .htaccess file after editing and exit from the editor.

Check Apache Configuration

While processing a request, the Apache web server looks for the first configuration file from a list of names in every directory that’s part of the path to the document. This is the case only if distributed configuration files are enabled for that directory. For example, let’s say your site has this in its configuration:

AccessFileName .htaccess

Before returning the document /var/www/html/drupal/index.php, the server will check the .htaccess file for directives unless they have been disabled using this setting:

AllowOverride None

When this AllowOverride directive is set to None and AllowOverrideList is set to None, then Apache will completely ignore the .htaccess files. In this case, the server will not even attempt to read .htaccess files in the filesystem. When this AllowOverride directive is set to All, then the directives are allowed in .htaccess files. So, make sure to set your AllowOverride directive to All.

So, if you get a “Your server is capable of using clean URLs, but it is not enabled.” warning message in the dashboard, updating AllowOverride from None to All should be enough to fix it. Do not forget, after making changes to your Apache configuration file, make sure to check the configuration with this command below:

$ sudo apachectl -t

or

$ sudo httpd -t

and restart the service if everything is okay.

$ sudo systemctl restart apache2

or, if you’re using an OS like CentOS, AlmaLinux, and Rocky Linux:

$ sudo systemctl restart httpd

If your Drupal website is running on Nginx, you most likely will not have this issue with Drupal clean URLs. And if you do, you just need to check your Nginx server block for your Drupal website. You can compare your Nginx server block with the one at https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/. There’s likely something missing or incorrectly set.

Since you are using Nginx, you do not need to check your .htaccess file as Nginx does not support that kind of configuration file.

That’s it all! You have learned how to fix the Drupal “Clean URLs” Not Working issue. Hopefully, you have a better understanding of the Clean URLs issues in Drupal.

PS. If you liked this post, please share it with your friends on the social networks using our share shortcuts, or simply leave a reply below. Thanks.

Leave a Comment