.htaccess !-f 规则不起作用 [英] .htaccess !-f rule not working

查看:41
本文介绍了.htaccess !-f 规则不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年来我一直在为我的 CMS 使用简单的 mod_rewrite 规则,现在正在制作一个新版本,我发现 rewriteCond 没有意义 - 我有标准的if is not a file",但我仍然看到 rewriterules即使他们不应该进行评估.我的重写代码:

I have been using simple mod_rewrite rules for my CMS for years and am now making a new version, I am seeing the rewriteCond not making sense- I have the standard "if is not a file" but I still see the rewriterules being evaluated even though they're not supposed to. My rewrite code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?page=$1
RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&var=$2

我加载/page/var 并且它作为 index.php?page=page&var=var 工作正常,但我尝试加载/css/file.css 并且它加载 index.php?page=css&var=file.css 即使/css/file.css 一个文件,所以整个重写部分甚至不应该被评估.

I load /page/var and it works fine as index.php?page=page&var=var, but I try to load /css/file.css and it loads index.php?page=css&var=file.css even though /css/file.css is a file, so the whole rewrite section shouldn't even be evaluated.

我从未见过 htaccess 明显违背其自身的逻辑,有人可以帮我解决这个问题吗?有没有人遇到过这样的事情?

I've never seen htaccess apparently defy its own logic, can someone help me figure this out? Has anyone ever run across anything like this?

推荐答案

RewriteCondition 仅适用于下一条规则.你想要这个:

The RewriteConditions only apply to the next rule. You want this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?page=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&var=$2

这篇关于.htaccess !-f 规则不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆