gpt4 book ai didi

apache - htaccess RewriteCond !-f 问题

转载 作者:行者123 更新时间:2023-12-02 09:55:35 24 4
gpt4 key购买 nike

更新:问题已解决
经过几个小时后,我终于明白问题出在文件夹权限上(757而不是755)。

该死,我感觉自己像个白痴,但至少,问题解决了:)

谢谢大家!

<小时/>

我的 .htaccess 和 mod_rewrite 遇到了一个奇怪的问题。

目前,我的根目录中有以下 .htaccess:

Options +FollowSymLinks
Options -MultiViews

RewriteEngine On

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.php [NC,L]

问题是:
我希望能够访问任何现有文件。

即: mysite.com/anydir/myfile.png -> 打开anydir/myfile.png
- mysite.com/anydir/script.php -> 打开anydir/script.php
- mysite.com/file.png -> 打开 file.png
- mysite.com/notadir/imnotafile -> 重写

但是,除了第二点之外,一切都有效。我的 test 文件夹中有一个 file.php,但是当我执行 mysite.com/test/file.php 时,它会不断重写它,而且它不应该...

我做错了什么?

最佳答案

可能会成功:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

更新1

在这部分代码:

RewriteRule ^index\.php$ - [L]

[L] 立即停止重写过程,不再应用任何规则。所以,

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.php [NC,L]

不被解释。

更新2:

服务器将遵循符号链接(symbolic link):

Options +FollowSymLinks

服务器将禁用多 View :

Options -MultiViews

将启用重写引擎:

RewriteEngine On

重写的基目录将为/:

RewriteBase /

如果请求与不存在的文件匹配,则继续:

RewriteCond %{REQUEST_FILENAME} !-f

如果请求与不存在的目录匹配,则继续:

RewriteCond %{REQUEST_FILENAME} !-d

重写index.php,在不敏感的情况下,并停止执行接下来的规则:

RewriteRule index.php [NC,L] 

所以,请尝试以下操作:

Options +FollowSymLinks
Options -MultiViews

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule index.php [NC,L]

关于apache - htaccess RewriteCond !-f 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15315833/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com