是的,另一個的RewriteCond,但我拉我的頭髮試圖得到它的工作....用於圖像的.htaccess的RewriteCond在另一個文件夾
我有Apache的根爲/var/www/html/
,並且如果我去http://example.com/
它正確使用/var/www/html/index.php
。
現在,問題是我有/var/www/images/example.com/
中的圖像。這是因爲我有一個需要動態的多站點設置。 PHP會整理使用哪個網站的代碼,因此移動圖片或對其進行別名不是一個選項,因爲它需要動態。
所以,我在我的/var/www/html/.htaccess
是這樣的:
Options -MultiViews -Indexes
RewriteEngine on
RewriteCond /var/www/images/example.com%{REQUEST_URI} -f
RewriteRule ^(.+)$ /var/www/images/example.com/$1 # <--- this DOES fire when the image exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /var/www/html/test.php?file=%{REQUEST_FILENAME} [END]
的test.php
只是回聲$_GET
,而奇怪的是,$_GET['file']
是/var/www/html/var
我在做什麼錯?
更新
好了,現在我有這個:
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^(.*)$ sites/%{HTTP_HOST}/$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php
我改變它,這樣的網站文件是主服務器的根目錄裏面。現在我不能讓它不允許直接訪問這些文件。
我想是這樣的:
http://example.com/images/fb.png - > /var/www/sites/example.com/images/fb.png http://example.com/sites/example.com/images/fb.png - > /var/www/index.php(顯示404) http://example.com/whatever - > /var/www/index.php
正如你所看到的,第二行的文件是該文件的全路徑直接和應該通關到index.php,而是它只是發送文件。如何防止這種情況?
好吧,解釋它。 – Sarke 2014-10-07 03:12:10
但是,我不想爲每個圖像使用PHP,因爲使用APACHE加載它們要快得多。我會解決一些問題,謝謝。 – Sarke 2014-10-07 03:12:53
即使在將圖像移動到'/ var/www/html /'後,我仍然會遇到同樣奇怪的重定向問題。 – Sarke 2014-10-07 03:27:56