Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 为什么这个.htaccess文件将静态文件路由到我们的前端控制器?_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 为什么这个.htaccess文件将静态文件路由到我们的前端控制器?

Apache 为什么这个.htaccess文件将静态文件路由到我们的前端控制器?,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,多年来,我们一直在使用以下.htaccess文件。我们使用的是apache2.4.7。出于某种原因,静态文件似乎正在撞击我们的前端控制器index.php 例如:https://example.com/apple-touch-icon.png由我们的前端控制器处理,因为我们可以看到响应标题包括X-Powered-by:PHP/5.5.9-1ubuntu4.3 有人能发现这个问题吗 <IfModule mod_rewrite.c> RewriteEngine On R

多年来,我们一直在使用以下
.htaccess
文件。我们使用的是
apache2.4.7
。出于某种原因,静态文件似乎正在撞击我们的前端控制器
index.php

例如:
https://example.com/apple-touch-icon.png
由我们的前端控制器处理,因为我们可以看到响应标题包括
X-Powered-by:PHP/5.5.9-1ubuntu4.3

有人能发现这个问题吗

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    ### Force SSL
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    ### Canonicalize codeigniter URLs

    # If your default controller is something other than
    # "welcome" you should probably change this
    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]

    # Enforce NO www
    RewriteCond %{HTTP_HOST} ^www [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

    # Removes access to the system folder by users.
    # Additionally this will allow you to create a System.php controller,
    # previously this would not have been possible.
    # 'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>

    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php

</IfModule>

重新启动发动机
重写基/
###强制SSL
重写cond%{HTTP:X-Forwarded-Proto}!https
重写规则^https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
###规范化codeigniter URL
#如果您的默认控制器不是
#“欢迎”您可能应该更改此选项
重写规则^(欢迎(/index)|索引(\.php)/?$/[L,R=301]
重写规则^(.*)/索引/?$$1[L,R=301]
#删除尾部斜杠(防止SEO重复内容问题)
重写cond%{REQUEST_FILENAME}-D
重写规则^(+)/$$1[L,R=301]
#不强制执行www
重写cond%{HTTP_HOST}^www[NC]
重写规则^(.*)$https://example.com/$1[L,R=301]
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
#在没有mod_重写的情况下,将404路由到前控制器
ErrorDocument 404/index.php

当找不到图像、js或css文件等资源时,您的
ErrorDocument
指令似乎导致了这种情况(加载
index.php

您可以注释掉此指令以避免此行为:

ErrorDocument 404 /index.php

注释掉
ErrorDocument 404/index.php
并重新加载相同的
png
文件。这就是罪魁祸首!也许你可以添加一个答案,这样我就可以标记为正确的答案。不太清楚为什么执行了
IfModule!mod_rewrite.c
?奇怪的是…
不应该执行吗?!如果执行了,那么你的相反结果呢块(
)也不能执行?!但是如果
错误文档
被处理了,那么如果
.png
存在也应该不会有问题(我认为它必须存在)?但是你在一个代理后面…这会有什么关系吗?顺便说一句,你的规则是“删除用户对系统文件夹的访问权”因为
RewriteCond
指令总是会失败,所以永远不会做任何事情,
REQUEST\u URI
服务器变量总是以斜杠开头。谢谢@MrWhite,我也需要查看
RewriteCond
指令!在代理(AWS ELB)后面也可能是罪魁祸首。但这可能只是在未启用mod_rewrite且静态资源不存在的情况下才会出现问题?哦,是的,没错。至少在显示的代码中,
ErrorDocument
仅在未加载
mod_rewrite
时才会触发。这就是问题所在。仍需要调查我的条件b的原因锁失败。现在,这解决了最初的问题,谢谢!