问题描述
我已经安装在一个子目录一个Zend的应用程序。不要问为什么我必须这样做的(不是我的preferred方法),但我没有这样的选择。在Zend的应用程序在一个子目录名为DSA。
I have setup a Zend application in a sub directory. Dont ask why I just had to do it that way (not my preferred method) but I don't have that choice. The Zend application resides in a subdirectory called dsa.
http://dsa.dev/dsa
我的.htaccess
My .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ public/index.php [QSA,L]
这工作,将引导应用程序。我可以去我的根目录和其它其他的东西没有任何问题。
This works and will bootstrap the application. I can go to my root directories and other directories for other things without any problems.
在我的application.ini我已经设置
In my application.ini I have set
resources.frontController.baseUrl = "/dsa".
在我的layout.phtml文件,如果我的var_dump路径,它看起来是这样的。
In my layout.phtml file if I var_dump the path it looks like this.
var_dump($this->baseUrl('css/main.css'));
http://dsa.dev/dsa/css/main.css
没有联系的工作,所有的CSS和JS文件没有链接正确。如果你打F12,看看他们你会得到一个404没有找到任何文件。什么我需要做的就是正确的路径,以显示文件。这是我第一次尝试设置的Zend在一个子目录,显然我不是在做正确的事情。我已阅读所有我能找到这个问题。感谢您的帮助。
None of the links work, all css and js files are not linking correctly. If you hit F12 and look at them you get a 404 not found for any file. What do I need to do to get the correct paths to show the files. This is the first time I have tried setting zend up in a sub directory and obviously I'm not doing something right. I have read everything I can find on this subject. Thanks for the help.
推荐答案
至少有一个问题,我看到的是,在的.htaccess
文件重写规则是不正确的。
At least one problem I see is that the rewrite rules in the .htaccess
file are incorrect.
考虑到这些规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ public/index.php [QSA,L]
这些规则等同于:
Those rules equate to:
的RewriteCond%{} REQUEST_FILENAME -s [OR]
#请求与大小> 0的常规文件的RewriteCond%{} REQUEST_FILENAME -l [OR]
#的要求是一个文件,它是一个符号链接的RewriteCond%{} REQUEST_FILENAME -d [OR]
#的要求是一个真实存在的目录
RewriteCond %{REQUEST_FILENAME} -s [OR]
# The request is a regular file with size > 0RewriteCond %{REQUEST_FILENAME} -l [OR]
# The request is to a file that is a symlinkRewriteCond %{REQUEST_FILENAME} -d [OR]
# The request is to a directory that exists
如果上述任何一项是真实的,该请求被改写为公共/ index.php文件
这是不正确的。如果请求的是存在磁盘上的文件,你不希望重写一遍;相反,你只是想提供该文件。
And if any of the above are true, the request is rewritten to public/index.php
which is not correct. If the request is for a file that exists on disk, you DO NOT want to rewrite it; instead you just want to serve that file.
正确的的.htaccess
文件看起来应该是这样的:
The correct .htaccess
file should look something like this:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]
这表示,如果该请求是与大小> 0,一个目录,或一个符号链接,然后将请求路由到请求的实际文件(重写规则^文件* $ -
)。如果没有这些条件都为真,则改写请求的index.php。
This says, if the request is for a file with size > 0, a directory, or a symlink, then route the request to the actual file requested (RewriteRule ^.*$ -
). If none of those conditions are true, then rewrite the request to index.php.
在一个单独的说明,我会继续前进,摆脱公开
目录干脆。取公开
的内容并把它们放在 / DSA
。 DSA
现在是你的公开
文件夹。你可以在任何地方存储你的应用程序
目录下的系统上,或者如果你必须把它包在 DSA
文件夹因文件系统的限制,确保规则添加到您的的.htaccess
文件,拒绝所有访问应用程序
文件夹。然后你只需要做出迅速改变你的的index.php
文件告诉它的正确路径应用程序
使用 APPLICATION_PATH
不变。
On a separate note, I would go ahead and get rid of the public
directory altogether. Take the contents of public
and put them in /dsa
. dsa
is now your public
folder. You can store your application
directory anywhere on the system, or if you have to place it in the dsa
folder due to filesystem restrictions, make sure to add a rule to your .htaccess
file that denies all access to the application
folder. Then you just need to make a quick change to your index.php
file telling it the correct path to application
using the APPLICATION_PATH
constant.
我相信,这两个变化应解决您的问题。
I believe those two changes should fix your problems.
这篇关于从子目录Zend的应用越来越Zend的布局链接正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!