title: .htaccess if-then-like selective rewrite
body: <pre><code>##### PART 1
  
  # IF:
  RewriteRule ^ac$ /ac05182018.pdf [R=301,NC,L]
  # THEN:
  RewriteCond %{DOCUMENT_ROOT}/downloads/$1 -f
  RewriteRule ^(.+\.(pdf))$ downloads/$1 [L]
  
  ##### PART 2
  
  # IF:
  RewriteRule ^ac64$ /ac64_05182018.pdf [R=301,NC,L]
  # THEN:
  RewriteRule ^(.*).(pdf)$ download.php?file=$1.$2 [L] 
  </code></pre>
  
  <p>"<strong>PART 1</strong>" works standalone (= if one requests <strong>http...mysite.com/ac</strong> then this rewrites to "<strong>http...mysite.com/downloads/ac05182018.pdf</strong>").  </p>
  
  <p>"<strong>PART 2</strong>" works standalone as well (= if one requests <strong>http...mysite.com/ac64</strong> then this rewrites to "<strong>http...mysite.com/download.php?file=ac64_05182018.pdf</strong>").</p>
  
  <p><em>I was wondering how to achieve the following</em>:</p>
  
  <p><strong>I need both of them (PART 1 &amp; 2) to be combined</strong>, so that either one will be executed, I mean that both work, depending on what file gets requested (either <strong>/ac</strong> or <strong>/ac64</strong>). </p>
  
  <p>When I do so though, "PART 1" no longer rewrites to "/downloads/ac05182018.pdf" and then stops executing the rest. Instead it rewrites to "http...mysite.com/download.php?file=downloads/ac05182018.pdf"... </p>
  
  <p>Any idea how to achive this?
  Something like:</p>
  
  <pre><code># IF:
  RewriteRule ^ac$ /ac05182018.pdf [R=301,NC,L]
  # THEN:
  RewriteCond %{DOCUMENT_ROOT}/downloads/$1 -f
  RewriteRule ^(.+\.(pdf))$ downloads/$1 [L]
  
  # ELSE
  
  # IF:
  RewriteRule ^ac64$ /ac64_05182018.pdf [R=301,NC,L]
  # THEN:
  RewriteRule ^(.*).(pdf)$ http...mysite.com/download.php?file=$1.$2 [L] 
  </code></pre>
  
  <p>Maybe with RewriteRule flag [S] or</p>
  
  <pre><code>&lt;If ... &gt;
  ...
  &lt;/If&gt;
  &lt;Else&gt;
  ...
  &lt;/Else&gt;
  </code></pre>
  
  <p>as both seen in the answers of <a href="https://stackoverflow.com/questions/11528634/how-to-write-if-else-mod-rewrite-statements-in-htaccess">How to write &quot;if...else&quot; mod_rewrite statements in .htaccess</a> ?</p>