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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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 Zend Framework设置htaccess文件_Apache_.htaccess_Zend Framework - Fatal编程技术网

Apache Zend Framework设置htaccess文件

Apache Zend Framework设置htaccess文件,apache,.htaccess,zend-framework,Apache,.htaccess,Zend Framework,我已经使用Zend框架很多年了,但是已经意识到我们正在修复的错误处理中的一些关键问题。 (我在这里发布了一个不同的问题:在那里解释故事) 我的问题很简单。Zend Framework的公共.htaccess文件是什么样子的 据报道, 然而,以上对我来说是新的-有人能解释它到底做了什么吗? 我当前的.htaccess文件中有很多301重定向代码,但出于本文的目的,我只在这里粘贴相关信息: ErrorDocument 404 http://www.mydomain.com/pagenotfound/

我已经使用Zend框架很多年了,但是已经意识到我们正在修复的错误处理中的一些关键问题。 (我在这里发布了一个不同的问题:在那里解释故事)

我的问题很简单。Zend Framework的公共.htaccess文件是什么样子的

据报道,

然而,以上对我来说是新的-有人能解释它到底做了什么吗? 我当前的.htaccess文件中有很多301重定向代码,但出于本文的目的,我只在这里粘贴相关信息:

ErrorDocument 404 http://www.mydomain.com/pagenotfound/
ErrorDocument 503 http://www.mydomain.com/service-unavailable/

RewriteCond %{REQUEST_URI} !^/liveagent
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule !\.(js|ico|gif|GIF|jpg|JPG|jpeg|png|PNG|pdf|css|html|xml|swf|php|mp3|mp4|webm|ogv|f4v|flv|txt|wsdl|css3|ttf|eot|svg|woff)$ index.php
以上内容对我们来说很好,基本上不允许“liveagent”和“blog”(Wordpress)目录与Zend一起运行,但我意识到我现在需要做以下更改:

ErrorDocument404肯定必须从代码中删除,因为Zend框架应该处理所有错误。但是,当我删除此项时,转到www.mydomain.com/this-does-not-exist.php这样的URL会导致404错误标准Apache页面-它不会加载ZF或ErrorController。这是因为上述规则中排除了“php”。我不想简单地删除它,因为我们有时希望能够访问根目录上的php文件,例如一个单独的“holding.php”文件,用于将站点置于维护模式

标准做法是什么?我应该删除php扩展吗?然而,这并不能解决其他404的问题 www.mydomain.com/this-not-exist.css 这也是上述规则中的排除(即CSS)

因此,我是否应该像上面提到的那样,将上述内容完全更改为Zend的.htaccess新代码


如果是这样的话,我是htaccess的初学者-我如何修改.htaccess代码以允许CSS、JS、视频文件等以及博客和liveagent目录被排除在Zend框架之外?

我将切换到标准的ZF重写规则,而不是使用长正则表达式重定向到index.php的规则

以下是标准
.htaccess
规则的功能说明:

RewriteCond %{REQUEST_FILENAME} -s [OR] # The request is a regular file with size > 0
RewriteCond %{REQUEST_FILENAME} -l [OR] # The request is to a file that is a symlink
RewriteCond %{REQUEST_FILENAME} -d [OR] # The request is to a directory that exists

# if any of the above conditions are true, then simply handle the request as-is
RewriteRule ^.*$ - [NC,L]

# if none of the above match, then rewrite to index.php
RewriteRule ^.*$ index.php [NC,L]
这些默认ZF规则不会阻止您访问现有的
php
文件或从文档根目录访问的任何其他文件。如果请求的文件存在,则该文件的请求将按原样提供。如果请求的文件不存在,则将请求转发到index.php

一旦请求被转发到ZF,如果没有匹配的路由,则调用ZF ErrorHandler并提供404页面(来自ZF)

使用stock ZF规则不会阻止您在应用程序和服务器设置中实现所需的行为,并且应该比您当前使用的正则表达式更高效。唯一真正改变的是,现在对不存在的文件的请求将由ZF的错误处理程序处理,而不再由Apache处理


希望这能回答您的问题,如果您不想澄清,请随时发表评论。

您是否愿意寻求解决方案?你愿意讨论吗?你知道有“评论”部分吗?我用辛勤的工作和耐心在你提供的链接中为你的问题写下了答案,你有没有对此进行解释?你是否对我的回答做出了评论并正确地提出了问题?你知道你真正想要的是什么吗?首先非常感谢你在另一个帖子上的详尽回复,我本想在我真正尝试后给你一个回复,我对任何冒犯表示歉意,因为我需要与另一位同事一起经历。另一方面,我认为,我的.htaccess文件在另一篇文章中没有提到——事实上,它导致了一个紧急问题(如上所述),我现在意识到这与我以前的文章是不同的问题,在回到ErrorController之前,我需要关注这个问题。因此出现了一个新问题,即询问标准htaccess是什么样子的。希望你能理解,再次感谢。当然,我理解。。。慢慢来:)非常感谢你的解释,这很有效。只是一个关于.htaccess的一般性问题——上面的第二个重写规则(如果上面的规则都不匹配,那么重写到index.php)——这个规则基本上只有在上面的规则失败时才会执行?基本上,如果满足上述条件之一,则执行第一条重写规则。然后,它停止运行。htaccess停止使用其他重写规则继续运行。否则,如果不执行,则完成第二条重写规则。这是正确的吗?
RewriteCond
类似于重写规则的if语句。因此,如果前3个RewriteCond中的任何一个为true,则执行规则
RewriteRule^.*$-[NC,L]
[L]
标志表示“last”,表示在该规则之后不应再处理任何规则。因此,如果文件确实存在,并且基于其中一个RewriteCond,那么请求将作为下一个重写规则处理,用于将所有内容重写到index.php的规则永远不会执行。如果RewriteCond都不为true,即请求的文件不存在,则执行index.php的第二个rewriterule。希望你能回答这个问题。
RewriteCond %{REQUEST_FILENAME} -s [OR] # The request is a regular file with size > 0
RewriteCond %{REQUEST_FILENAME} -l [OR] # The request is to a file that is a symlink
RewriteCond %{REQUEST_FILENAME} -d [OR] # The request is to a directory that exists

# if any of the above conditions are true, then simply handle the request as-is
RewriteRule ^.*$ - [NC,L]

# if none of the above match, then rewrite to index.php
RewriteRule ^.*$ index.php [NC,L]