Setting Up Clean URL’s for Drupal With .htaccess
By default, Drupal passes path arguments to itself via its dynamically generated URLs. This results in URLs that look like “http://www.example.com/?q=node/83.” This can make URLs hard to read and it prevents some search engines from indexing the pages with these URLs. Research suggests this may not be as great an issue for some of the major search engines as it once was, however it is worth noting the recommendation from Google’s webmaster guidelines stating:
If you decide to use dynamic pages (i.e., the 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.
You can tell Drupal to use “clean URLs”, eliminating the “?q=” in internal URLs. Note that this works only for Apache servers which have the mod_rewrite Apache module configured and mod_rewrite enabled in httpd.conf configuration file.
Sometimes when you’re setting up a new install of Drupal CMS, if you want Clean URL’s enabled, you might encounter a situation where the installer (or configuration manager) says your server is not setup to handle Clean URL’s. If you don’t have access to Apache’s httpd.con configuration file (as in shared hosting scenarios), you can easily use .htaccess to fix this issue.
All you have to so is create an .htaccess file in your install’s root directory with the following directives
| # # Apache/PHP/Drupal settings: ## Protect files and directories from prying eyes. Order allow,deny Options -Indexes # Follow symbolic links in this directory. # Make Drupal handle any 404 errors. # Force simple error message for requests for non-existent favicon.ico. # Set the default handler. # Override PHP settings. More in sites/default/settings.php # PHP 5, Apache 1 and 2. # Requires mod_expires to be enabled. # Cache all files for 2 weeks after access (A). # Do not cache dynamically generated pages. # If your site can be accessed both with and without the ‘www.’ prefix, you # Modify the RewriteBase if you are using Drupal in a subdirectory or in a # Rewrite URLs of the form ‘x’ to the form ‘index.php?q=x’. |
That’s all there is to it !!
August 17th, 2008 at 2:02 pm
[…] Go to the author’s original blog: Setting Up Clean URL’s for Drupal With .htaccess […]