2017-08-14 56 views
0

我有这个网址 - 这是工作htaccess的重定向403添加文件夹的路径,如果没有找到

http://pic.site.com/images/nofeymata/102.jpg 

,我有我的应用程序这个网址 - ,我得到403错误

http://pic.site.com/nofeymata/102.jpg 

我需要一种方式“添加” images的路径只有当我得到403 eroor

我htaccess的锁是这样的:

RewriteEngine On 
RewriteCond %{QUERY_STRING} ^width=\d+&height=\d+&image=(.*) 
RewriteRule^%1? 

RewriteEngine On 
RewriteCond %{THE_REQUEST} imageget\.php [NC] 
RewriteRule^- [NC,L] 

#disallow access to other php files 
RewriteCond %{THE_REQUEST} .+\.php [NC] 
RewriteRule^- [F,L] 

所以,当我的应用程序SEACH此URL

http://pic.site.com/nofeymata/102.jpg 

,并得到403 WIL redrict到

http://pic.site.com/images/nofeymata/102.jpg 

这部分/nofeymata/102.jpg是随机的可以是任何文件夹和文件

我已经tryed

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !^/images[NC] 
RewriteRule^/images%{REQUEST_URI} [R=403,L] 

thi s的工作,但是当我查询这个

http://pic.site.com/images/nofeymata/102.jpg 

我得到

http://pic.site.com/images/images/nofeymata/102.jpg 

我不能figre出来,谢谢!

+0

会是怎样的的目的是什么?您为什么要重定向,而不是在请求的URL下输出错误代码?借此,您将防止客户端将403状态码与实际URL正确关联。 – CBroe

+0

它只是图像的cdn – shlomicohen

回答

0

我添加此

ErrorDocument 403 /403.php 

,并在404.php文件

<?php 

$url = $_SERVER["REQUEST_URI"]; 
$http = $_SERVER["SERVER_NAME"]."/images".$url ; 
header("Location: http://".$http); /* Redirect browser */ 
?> 

及其工作现在完美好sulotion