我一直在研究自己的mvc框架以进一步学习我的Web应用程序,但在服务静态资源时遇到问题。我试图在应用程序中有一个入口点,也就是前端控制器,所以在我的项目/我有一个.htaccess文件,将所有请求重定向到应用程序/文件夹,其中另一个.htaccess将请求URI传递给index.php (在app /中)将请求委托给适当的控制器。apache不能正确提供静态内容
但是,当我尝试提供静态内容(如javascript或级联样式表)时,我仍然通过app/index.php重定向。我在/var/log/apache2/errors.log中也得到了“favicon.ico不存在于/ var/www”错误(可能是因为〜/ www的符号链接)。我不希望因为我的项目的根目录的根目录下面的.htaccess文件来:
<IfModule mod_rewrite.c>
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase/
# ----------------------------------------------------------------------
# Suppress the "www." at the beginning of URLs
# ----------------------------------------------------------------------
# The same content should never be available under two different URLs - especially not with and
# without "www." at the beginning, since this can cause SEO problems (duplicate content).
# That's why you should choose one of the alternatives and redirect the other one.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule^http://%1%{REQUEST_URI} [R=301,L]
#----------------------------------------------------------------------
# Route static resources to respective files
#----------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond public/$0 -f
RewriteRule ^.+\.(jpg|gif|png|ico|css|js)$ /public/$0 [L]
#----------------------------------------------------------------------
# Redirect all other requests to the app folder
#----------------------------------------------------------------------
RewriteRule ^$ app/ [L]
RewriteRule (.*) app/$1 [L]
</IfModule>
而这里的.htaccess在我的应用程序/文件夹:
<IfModule mod_rewrite.c>
RewriteEngine On
# ensure request is not path to filename or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# redirect all requests to index.php?url=PATHNAME
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
为什么”我是否正确提供静态内容?如果我不是试图将所有静态请求发送到public /,这是我的css,jpg,png,js等文件所在的位置,这对我来说是有意义的。但我有一个RewriteCond规则在那里将这些文件的请求发送给公共目录...令人困惑?
我尝试删除'RewriteCond%{REQUEST_FILENAME}!-f',因为它过滤所有文件,但仍然不起作用。 – Andrew