Search code examples
regexapachemod-rewritecache-controlclean-urls

mod_rewrite condition not firing?


Before I redirect the user, I want to check if the redirected-to-file actually exists. Now the following code works yet right when I add the bit which is currently commented out it skips the rewrite rule altogether.

<IfModule mod_rewrite.c>   
  RewriteEngine on    
  RewriteBase /   
  # RewriteCond cache/$1.html -f      
  RewriteRule ^([^/]+)/?([^/]*) cache/$1.html [L]    
<IfModule>     

Ive been struggling on this for three days now, any help would be greatly appreciated!!!


Solution

  • In # RewriteCond cache/$1.html -f the $1 doesn't refer to anything, so it is going to skip your RewriteRule.

    Try

    RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI}.html -s
    

    RewriteCond Documentation