2016-02-25 123 views
2

我试图从图像路径中删除目录/images/。当图像通过它存储在/images/表单提交我创建了一个htaccess的规则去除图像目录,但我不知道它与图像,我得到一个404从图像路径删除目录htaccess

Options +FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase/

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

我需要创建一个PHP页面来提供图像并使用htaccess删除该页面?我们的目标是让domain.com/img.png

感谢

回答

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] 
+0

完美的作品谢谢! – SamXronn

+0

是否也可以拒绝对目录的访问? – SamXronn

+0

查看拒绝直接访问'/ images /'的更新答案。 – anubhava