Enable clean URLs in Drupal

 In Drupal, clean URLs are enabled by default and can't be disabled. However, a rewrite module must be installed on your web server.

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

Example of proper 'Clean URLs'

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

Example of 'Clean URLs' not working

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

Server configuration for Clean URLs

Enable mod_rewrite for Apache. You can talk to your web host or consult the Apache documentation for mod_rewrite to get more information on how to do this. At a minimum, this will involve making sure that mod_rewrite is enabled for your installation of Apache.

To test if mod_rewrite is available in Apache2, you can type the following at a command prompt, to list all installed Apache modules:

apache2ctl -M 

On some systems this command may be:

apachectl -M 

Or,

httpd -M 

In the output, check to see if the rewrite_module is included in the list of modules.

If the rewrite module is not in the list, it will have to be either compiled-in or made available as a loadable module. Generally speaking, you can tell Apache to load the module by including

LoadModule rewrite_module modules/mod_rewrite.so

AddModule mod_rewrite.c

in your Apache configuration file (see below for information on the configuration file). Be sure to uncomment AddModule mod_rewrite.c, if it is in your configuration file but has been commented out. The following may work to enable the module without editing any files:

a2enmod rewrite 

Note that these approaches may not work for all combinations of operating system and Apache server -- consult the Apache documentation that came with your Apache software for the correct syntax.

Remember to restart Apache for the new configuration to take effect.

The next step is to locate the appropriate Apache configuration file for your site. Depending on your server configuration, the appropriate Apache configuration file could be httpd.conf, a virtual-host-specific file (vhost.conf), a specific site file (e.g. "default"), or apache2.conf. They are usually located in /etc/httpd/conf, /etc/apache2, or a sub-directory; if not, try the command:

find /etc -name httpd* 

Or,

find /etc -name apache2* 

The next step is to copy or include the Drupal-specific settings directly into your configuration file ( .htaccess file).

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !=/favicon.ico

RewriteRule ^ index.php [L]

Or this example on a Debian 8 + Apache2 + ISPConfig, using wildcard to match all sites installed:

<Directory /var/www/clients/*/*/web/>

  RewriteEngine on

  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

</Directory> 

3 comments:

Logan Smith said...
This comment has been removed by a blog administrator.
Innomatics said...
This comment has been removed by a blog administrator.
Ronak Vachhani said...

Amazing Content 😊

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...