Drupal 7 - how to enable Clean URLs

In this blog post I'm going to tell you more about Clean URLs for Drupal 7. I'm going to try to enable clean URLs for my site at the same time as well.

By default, Drupal & generates URLs for pages with "q" parameter "http://www.marekpisch.com/?q=node/1." This style of URLs can be hard to read and can prevent some search engines from indexing all the pages of the site (even this is not true anymore for major search engines as it was before).

But information from Google's webmaster guidelines means that clean URLs are important:
"If you decide to use dynamic pages (URL contains a "?" character), be aware that not every search engine spider crawls dynamic pages as well as static pages. It helps to keep the parameters short and the number of them few.

I personally like clean URLs for some shortcuts direct in URLs, for example http://www.marekpisch.com/admin will get me directly into administrator interface.

I've been allays running Drupal on Apache web servers so information provided here is for the most common server setup (Apache running on Unix/Linux, mod_rewrite configured and enabled).

Before enabling clean URLs, we may need to prepare our server for it. There are two ways to do it: httpd.conf or .htaccess file changes. Most my sites (marekpisch.com as well) and small business sites are using shared hosting environment, so using .htaccess file is only one available option.

Standard Drupal installation package contains a sample .htaccess file which supports clean URLs. Before trying to enable Clean URLs, make sure this file exists in your Drupal installation directory. It is a hidden file so sometimes it is missed when copying source code between directories. Installer test for compatibility with Clean URLs is a part of the installation process in Drupal 7.

For my case default installation of Drupal 7 did not enable Clean URLs automatically. But enable them later is easy when server is properly configured.
When you navigate to the Clean URLs configuration page (Administer > Configuration > Search and metadata > Clean URLs) you can enable/disable this feature. See picture below.

You can enable or disable this feature anytime by following these steps:

1. Navigate to the Clean URLs config page (Administer > Configuration > Search and metadata)
2. Wait for the automated test to run and finish.
3. Check or un-check the Enable clean URLs check box
4. Click "Save configuration"

This is URL to this blog post without Clean URLs: http://marekpisch.com/?q=node/8
And this one to the same post with URL enabled: http://marekpisch.com/node/8

More information about Clean URLs for Drupal 7 is available here: http://drupal.org/node/15365

Another contributed modules such as Path and Path Auto are important for SEO and URLs generation for Drupal as well. I'll write about those modules sometimes in the future.

Blog Image: