【问题标题】:.htaccess allow image to display directly.htaccess 允许图像直接显示
【发布时间】:2015-09-01 08:11:24
【问题描述】:

我有很多文件,包括图像、php&js 脚本和子文件夹。 我需要使用 .htaccess 将任何 uri 重定向到 index.php。
例如:

www.example.com/test should be redirect to index.php

但不应将图像重定向到 index.php。相反,它应该直接在浏览器中打印。
例如:

www.example.com/sample.jpg should display sample.jpg.

我在 .htaccess 代码中使用以下代码:

RewriteEngine On  
RewriteRule ^(.*)$ index.php

谁能解释一下如何让图片显示?

【问题讨论】:

    标签: php regex apache .htaccess redirect


    【解决方案1】:

    在规则前添加条件以跳过 image/css/js 文件目录:

    RewriteEngine On
    
    RewriteRule !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ index.php [L,NC]
    

    【讨论】:

    • 但需要将任何 uri 重定向到 index.php,就好像文件存在或不存在一样。如果是.jpg/.gif文件,应该在浏览器中显示,不重定向。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 2010-11-17
    相关资源
    最近更新 更多