Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I migrate a static html site to drupal CMS, most content I just copied the html for now and want to leave it as is and make the relative links to pdf files working. Drupal has all files in this dir: ( I copied the whole tree of FORMER SUB DIRS - nice, want to keep that )


So all relative links in the CMS contents become now:

I want to check if the file exists and then rewrite the url

RewriteEngine On
RewriteCond     /var/www/{REQUEST_URI MINUS "node/"} -f
RewriteRule     (.*)$ /sites/$1  [R]

How could i achieve that?

share|improve this question
up vote 2 down vote accepted

You'll need RewriteCond backreferences. Please see the manual for details.

Roughly (but I have no way of testing it at the moment):

RewriteCond     %{REQUEST_URI MINUS} ^/node(.*)
RewriteCond     /var/www/ -f

The %1 is a RewriteCond backreference, as opposed to a RewriteRule backreference (which would be $1)

share|improve this answer

works that way

RewriteCond     %{REQUEST_URI} ^/node(.*)
RewriteCond     /var/www/ -f
RewriteRule     .* /sites/  [L]

(but unfortunately i forgot that there is another level of subdirs directly under docroot which apache cannot know.)

I want to figure out if I set drupal path alias for all the top level documents - I'll see

share|improve this answer
You can edit your original question. Anyway, if you need some conditionals, you may want to use [E:VARNAME:value] in your rules so as to set variables depending on certain conditions and then consume them inside other rules (or generally elsewhere) ... – 0xC0000022L Mar 7 '11 at 13:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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