Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 )

 DOCROOT/sites/mydomain.xyz/files/FORMER/SUB/DIRS/filename.pdf

So all relative links in the CMS contents become now:

 http://mydomain.xyz/node/FORMER/SUB/DIRS/filename.pdf

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

RewriteEngine On
RewriteCond     /var/www/mydomain.xyz/sites/mydomain.xyz/files/%{REQUEST_URI MINUS "node/"} -f
RewriteRule     (.*)$ /sites/mydomain.xyz/files/$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/mydomain.xyz/sites/mydomain.xyz/files/%1 -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/schottdorf.de/sites/schottdorf.de/files%1 -f
RewriteRule     .* /sites/schottdorf.de/files/%1  [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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .