与静态文件的.htaccess重写规则,给了我404,我缺少的是什么? [英] .htaccess rewrite rule with static files gives me 404, what I'm missing?

查看:142
本文介绍了与静态文件的.htaccess重写规则,给了我404,我缺少的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目(​​捷希凯)在网​​络/ CSS / * 网​​络/ index.php文件和资产>,网​​络/ IMG / * 等。我已经放在下面的的.htaccess 文件中的公共HTML文件夹的根目录下:

My project (Silex) has a front controller web/index.php and assets in web/css/*, web/img/* and so on. I've placed the following .htaccess file in the root of the public html folder:

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteBase web
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>

每一项请求应rewrited到网络文件夹(的RewriteBase网站指令),如果文件不存在(! - ˚F),它应该被路由到前端控制器。

Every request should be rewrited to web folder (RewriteBase web directive) and if file doesn't exist (!-f) it should be routed to the front controller.

这是行不通的:

<img src="/img/myimage.png" alt="" />

文件 myimage.png 存在,但要求 /img/myimage.png 给我一个404的文件夹。如果我修改的路径, /web/img/mmyimage.png 它的工作原理。

File myimage.png exists, but request for /img/myimage.png gives me a 404 folder. If I modify the path to /web/img/mmyimage.png it works.

有我丢失的东西?

推荐答案

我设法与这些线路修复它:

I managed to fix it with these lines:

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On

    RewriteCond %{DOCUMENT_ROOT}/web/$1 -f
    RewriteRule ^(.+?)/?$ /web/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ web/index.php [QSA,L]
</IfModule>

这篇关于与静态文件的.htaccess重写规则,给了我404,我缺少的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆