从图像路径htaccess

时间:2016-02-25 22:52:31

标签: php image apache .htaccess mod-rewrite

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

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

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

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

由于

1 个答案:

答案 0 :(得分: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]