2013-04-15 46 views
1

我這個項目的結構 enter image description here如何在htaccess中編寫重寫規則以允許訪問項目中的另一個文件夾?

我保存圖像的文件夾數據/圖像。 我想允許通過直接鏈接訪問此文件夾。 我的.htaccess是

RewriteEngine On 
# The following rule tells Apache that if the requested filename 
# exists, simply serve it. 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do 
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work 
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution. 
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$ 
RewriteRule ^(.*)$ - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

怎麼辦?

+0

您的網站根目錄是「* public *」文件夾嗎?在這種情況下,您無權訪問,因爲它在層次結構中更高。如果可以通過* HTTP *訪問其內容,則必須將圖像文件夾移動到公用文件夾中。然後,您可以使用像「RewriteCond%{REQUEST_URI}」/ images /「'這樣的規則來允許訪問。 – insertusernamehere

+0

如果'data/images'低於您的文檔根目錄,您的規則已經足夠。 –

+0

是的,web根目錄是公共文件夾 – BILL

回答

2

正如暗示的意見,你不能因爲你的圖片文件夾是文檔根目錄上面做到這一點只需通過修改htaccess文件。您需要將data/images文件夾移動到public/images,或者創建從public/imagesdata/images的符號鏈接。然後你的圖片應該可以在沒有任何htaccess變化的情況