I have an url rewriting issue with my drupal 7

I'm trying to rewrite for example index.php?q=categorie&categorie=laars to categorie/laars.html

So I downloaded the default drupal 7 .htaccess file from https://code.google.com/p/drupalgooglecode/source/browse/trunk/.htaccess

Then in the section

# Various rewrite rules.
<IfModule mod_rewrite.c>

I added:

RewriteRule ^categorie/([^/]*)\.html$ index.php?q=categorie&categorie=$1 [L]

Above the default (I also tried below but that didn't rewrite the url):

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

But it doesn't seem to work. When the rewrite rule is added, my site's layout is all messed up. As if the themes/css is not loaded anymore. The url does rewrite as I want, but it looks like drupal doesn't know where the theme files are. What may be the cause of this?

Thanks! Stece

UPDATE: is it possible that url-rewriting of .htaccess conflicts with the drupal clean-url's module? Because theming that doesn't load, feels like something is conflicting. Not sure...

UPDATE2: also tried using a custom module with the hook_url_inbound_alter, but that's not working with me either (https://stackoverflow.com/questions/17176589/drupal-hook-url-inbound-alter-not-altering-my-url). That question is on stackoverflow, for some reason I hoped to get a quicker solution their.

  • im curious to why you need a .html extension to your pages? all url rewriting is done via the pathauto module. Jun 16, 2013 at 16:03
  • the extra .html was a request of the client. He thinks that it will slightly improve SEO. But if it works without the .html it's ok too. However when I try to remove it from the code above or the answer from Jerdiggity, it still doens't work. Jun 20, 2013 at 9:40
  • this might help shed some light on the .html seo thing: blackhatworld.com/blackhat-seo/blogging/… -- i personally would say its no difference the way serp's see your site. Jun 20, 2013 at 12:26
  • Do you have a hook_menu implementation for categorie? If so could you add the code. It seems like you can skip this whole rewrite thing altogether and just do it with simple hook_menu and pathauto as others have suggested.
    – Beebee
    Jan 20, 2014 at 13:10

3 Answers 3


Maybe I am missing something, but you shouldn't need the .htaccess rewrite.

It is likely that the 'conflict' is it rewriting the path to your styles. View the source and check what happens when you try to navigate to your css etc.

To achieve this effect all you should need to do (unless I am missing something) is to enable clean URLs, this will remove the index.php?q=.

Then to add .html go to admin/config/search/path/patterns (with pathauto installed) and add .html after [node:title] or [term:name], whichever you are using.

So your patterns would look like:


This assumes your site is located at http://www.example.com:

RewriteCond %{QUERY_STRING} ^(q)=(categorie)&(categorie)=(.+)$ [NC]
RewriteRule ^$ http://www\.example\.com/%3/%4\.html${pages:%1¦NULL}? [L]

Hope that helps... :)

  • It also removes theming form the website. Is it possible that url rewriting in .htaccess conflicts with the default clean-url module or something? Jun 17, 2013 at 9:22

As if the themes/css is not loaded anymore.

Are the styles loading? Check the resources in DevTools/Firebug to see the URL request and make sure it isn't returning 404. Knowing the bad request path(s) would help to answer your question better...

This is a shot in the dark, but check to make sure static styles are defined in your .info & dynamic styles are called using drupal_get_path() from template.php

Clean URLs + PathAuto is definitely the easiest solution to add the .html extension- this post explains how pretty well.

Not the answer you're looking for? Browse other questions tagged or ask your own question.