By default, Drupal uses dynamically generated URLs which are less search engine friendly as they may prevent search engines from indexing pages. The URLs are in this format: http://www.domain.com/?q=node/81. If you want your pages to be better indexed and the addresses more readable to the human being, you can enable clean URLs which remove the special characters “?q=”.
For Drupal 7, clean URLs are enabled automatically in the installation if there is no compatibility issue, but the activation may fail due to some reasons like the disallowance of URL rewrite. At this time, you will need to enable the feature manually after the installation is completed. As an unsuccessful activation results from unsuitable server configurations in most cases, we now start from making configuration right.
Make Sure the Server Is Properly Configured
To allow URL rewriting, the rewrite engine for the web server must be turned on. In a shared hosting environment, it is probable that you need to contact your hosting provider to ask them to do the job for you.
For an Apache web server, mod_rewrite module must be installed and enabled. Besides, you also need to check whether .htaccess file is included in your Drupal installation.
A sample .htaccess file is contained in a standard installation, but if you install Drupal manually, you may forget to copy the file to your server due to the a-little-bit-strange file name.
Enable Clean URLs in Drupal 7
Enabling clean URLs in the Drupal admin panel is simple, with several clicks required only. When you have logged into the dashboard, follow the steps below.
- Locate Configuration in the main menu and click on it.
- Find the section for Search and Metadata and click on the link for Clean URLs.
- Tick the checkbox before Enable clean URLs and click on the Save configuration button.
The steps above work only when your site passes the clean URL test. Sometimes you cannot get the test running properly and the page may just refresh itself but does not lead you to any new page. In this case, there is a trick – you can visit the clean URL admin page http://domain.com/admin/config/search/clean-urls which will get you a checkbox for enabling clean URLs. Note that there is no query string “?q=” in the address of the admin page. Misuse can lead to a negative result.
Now that you have changed the URL structure, check the pages on your site to see whether the changes have come into effect. If everything is right, you can stop here, but there might be another result – many errors appear when you try to access your site.
When an error happens, you may not be able to access the admin panel again to undo the configuration. At this time, you have to manually disable clean URLs and then check your server configuration again.
Disable Clean URLs
In the situation that you are locked out of administration due to clean URL issues, you can disable clean URLs by following the steps below.
- Use http://domain.com/?q=user to log into your site. You may receive a 404 error as clean URLs are still in use.
- Visit http://domain.com/?q=admin/config/search/clean-urls, which will show you the clean URL admin page with a checkbox that allows you to disable the feature.