2017-08-14 55 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