【问题标题】:Remove directory from image path htaccess从图像路径 htaccess 中删除目录
【发布时间】:2016-02-25 22:52:30
【问题描述】:

我正在尝试从图像路径中删除目录/images/。当通过存储在/images/ 中的表单提交图像时,我创建了一个 htaccess 规则来删除图像目录,但我不确定它是否适用于图像,因为我得到了 404。

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^images/(.*)$ /$1 [L,NC,R]

我是否需要创建一个 php 页面来提供图像并使用 htaccess 删除该页面?目标是拥有 domain.com/img.png

谢谢

【问题讨论】:

    标签: php image apache .htaccess mod-rewrite


    【解决方案1】:

    这应该适合你:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /
    
    # deny direct access to /images/
    RewriteCond %{THE_REQUEST} /images/ [NC]
    RewriteRule ^ - [F]
    
    # internal rewrite to add /images/ silently
    RewriteCond %{REQUEST_URI} !/images/ [NC]
    RewriteRule \.(?:jpe?g|gif|bmp|png|tiff|ico)$ images%{REQUEST_URI} [L,NC]
    

    【讨论】:

    • 是否也可以拒绝访问该目录?
    • 查看拒绝直接访问/images/的更新答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多