开发者

mod_rewrite condition not firing?

开发者 https://www.devze.com 2023-02-22 20:52 出处:网络
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 r

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 struggl开发者_开发技巧ing on this for three days now, any help would be greatly appreciated!!!


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


My first impression is to check that cache/$1.html exists and that you aren't accidentally redirecting from myserver.com/index.html -> to -> myserver.com/cache/index.html.html

0

精彩评论

暂无评论...
验证码 换一张
取 消