I'm having an issue that is similar to this question.

In short, I'm trying to use some custom RewriteRules to point old (no longer functioning) urls to new working urls. To accomplish this, I'm trying something similar to:

RewriteRule ^oldsite/directory/ABCD(.*)\.html? /search/$1 [NC,R=301,L]

The issue is, this is completely ignored (as mentioned in the question linked to before.) However, I've noticed that if I move my RewriteRule from the bottom of the .htaccess file up a bit to line 112, which is:

# 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]

The the rewrite rules work just perfectly fine. The answer to the previous question said that you couldn't use a clean url destination. So this would work:

RewriteRule ^home/code/([^/]+) ?q=home/software/node/&code=$1

but this won't:

RewriteRule ^home/code/([^/]+) home/software/node?code=$1

Problem is neither of them seem to work for me. I remember a few D7 updates ago there was an update to the .htaccess files. Could that be effecting this? Is there another way around this issue to get RewriteRules to work?

2 Answers 2


Just put it above line 112. The reason it doesn't work below that is line 117:

RewriteRule ^ index.php [L]

that [L] means that if the conditions above it match and that rule is applied no further rules will be checked. If you put it above that line clean or non-clean style url will work fine but probably don't want to include an L on the end of your rule so use:

RewriteRule ^home/code/([^/]+) home/software/node?code=$1 [R=301,NC]

on line 111 (well whatever actual content rule you need).


RewriteRule has issues for some reason, but RedirectMatch doesn't. I suspect this is because the RedirectMatch is part of mod_alias, and the RewriteRule stuff is part of mod_rewrite. Both get applied, but at different points in the processing, and is likely RedirectMatch is better suited in this situation.

So instead of:

RewriteRule ^oldsite/directory/ABCD(.*)\.html? /search/$1 [NC,R=301,L]


RedirectMatch 301 /oldsite/directory/ABCD(.*).html$ /search/$1

Not sure why this works, but it does work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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