[英]Apache rewrite ignore images for processing permissions in PHP
我對REGEX不熟悉,並且在.htaccess中有以下代碼
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^uploads/(.*)$ download.php?file=$1 [QSA,L]
並且download.php文件的內容是
require_once ('users.php'); // user session
$allowedExtensions = array(
'.jpg',
'.png',
'.gif',
'.ico',
);
$extension = substr($_GET['file'], -4);
// Requested file is not in allowed extension and is not a logged in user
If (!in_array($extension, $allowedExtensions) && !is_user()) {
echo '<h1>Sorry, only members can download the files.</h1>';
exit();
}
它很棒,它的作用是:
但是我認為download.php腳本中的每次檢查開銷都太大,因此我試圖直接從.htaccess重寫規則中忽略這些圖像。 看起來我必須更改以下代碼
RewriteRule ^uploads/(.*)$ download.php?file=$1 [QSA,L]
在下載到download.php之前跳過圖像,但不知道如何。
謝謝!
只需添加排除那些擴展的條件即可:
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|bmp)$ [NC]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^uploads/(.*)$ download.php?file=$1 [QSA,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.