仅在文件不存在时重写 [英] Rewriting only when a file doesn't exist

查看:57
本文介绍了仅在文件不存在时重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.htaccess文件,如下所示:

I've got a .htaccess file as it follows:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ index.php [NC,L]

我已经在Web目录中找到了该文件.如果有文件,是否有任何方法可以强制该规则停止重写?

I've got this file in my web directory. Is there any way to force this rule to stop rewriting if there's a file?

例如:我有一个css/style.css文件,但是服务器返回404,因为mod_rewrite规则有效.如果我关闭mod_rewrite,则会找到该文件.

For example: I've got a css/style.css file but the server returns 404 because the mod_rewrite rule works. If I turn the mod_rewrite off, the file is found.

推荐答案

是的,有:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^(.+) - [PT,L]

  RewriteRule ^assets/(.*)$ public/assets/$1 [L]
</IfModule>

第一个条件块和第一个规则适用于现有文件和文件夹,第二个规则是在没有文件或文件夹的情况下应进行的实际重写.

First block of conditions and the first rule is applied to existing files and folders, and the second rule if an actual rewrite that should happen if there is no file or folder.

这篇关于仅在文件不存在时重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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