get clean urls working for drupal 7 with htaccess


I think this is a very common problem for Drupal users. I have been Googling for an answer for hours. Unfortunately, all the answers from the Internet did not work for me. But in this process, I learnt a lot on the combination of Apache2 and Drupal. Here is the step-by-step solution.

1. find the Apache2 file httpd.conf, if you donot know where is this file, you can use command line: locate httpd.conf

2. add the following code snippet into httpd.conf

<Directory “/var/www/your-website-dir">
       AllowOverride All 
</Directory>

 AccessFileName .htaccess

3. enable the rewrite module by:
       a2enmod rewrite

4. restart the Apach2 server by:

      /etc/init.d/apache2 restart

Then, you can go to your Drupal admin interface to test it. 
http://testenglish.info/admin/config/search/clean-urls
Similar url like this.

Note: If this still does not work for you. You can add the following line in the .htaccess file located in your Drupal home directory:

    RewriteEngine on
    RewriteBase /
    # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
    # Pass all requests not referring directly to files in the filesystem to
    # index.php. Clean URLs are handled in drupal_environment_initialize().
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^ index.php [L]


PS. Get the clean urls working is an essential step for the Drupal Boost plugin. Withe Drupal Boost plugin, you can static your Drupal website such that you can save some resource and get your website fast.

0 comments

Popular Posts

无觅相关文章插件,迅速提升网站流量