2015-09-28 69 views
1

我希望能夠在兩個子目錄.htaccess的搜索搜索我希望能夠在兩個子目錄.htaccess的

我有以下目錄結構

dir

我的問題是:

當例如一個請求上

resources/images/players_small_pigs/BMI10.png 

正在接收,我希望能夠在路徑搜索

webapp/public/resources/images/players_small_pigs/BMI10.png 

是文件沒有找到這裏,我想繼續在

webapp/adminpanel/resources/images/players_small_pigs/BMI10.png 

搜索可以有一個人幫助我通過使用.htaccess文件來實現它的功能?整個文件夾結構資源,視圖和web服務中的問題,我認爲它可能是一個糟糕的結構,我可能應該把它們全部放在一個文件夾中,而不是在管理員和公共文件夾之間進行分割,你推薦?

我在.htaccess下面的代碼:

Options +FollowSymLinks 
RewriteEngine on 

RewriteRule ^(resources/.*)$ /webapp/public/$1 [L] 

RewriteRule ^(resources/.*)$ /webapp/adminpanel/$1 [L] 

RewriteRule ^webservices/(.*)$ /webapp/public/webservices/$1 [L] 
RewriteRule ^webservices/(.*)$ /webapp/adminpanel/webservices/$1 [L] 

RewriteRule ^(public/resources/images/)(sponsors/)?(.*)$ /webapp/$1$2$3 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} adminpanel 
RewriteRule (.*) /webapp/adminpanel/views/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !adminpanel 
RewriteRule (.*) /webapp/public/views/$1 [L] 

RewriteRule ^$ /webapp/public/views/index.php [L] 
+0

爲什麼你需要「搜索」的圖像,尤其是在這個層面上(htaccess的/重寫)?爲什麼你的應用程序不知道它想顯示的圖像在哪裏? //如果你真的想實現這一點,那麼你將需要使用'RewriteCond',只有它可以檢查文件是否存在。 – CBroe

回答

0

你可以給以下規則一試:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} ^/resources 
RewriteCond %{DOCUMENT_ROOT}/webapp/public%{REQUEST_URI} -f 
RewriteRule^%{DOCUMENT_ROOT}/webapp/public%{REQUEST_URI} [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} ^/resources 
RewriteCond %{DOCUMENT_ROOT}/webapp/adminpanel%{REQUEST_URI} -f 
RewriteRule^%{DOCUMENT_ROOT}/webapp/adminpanel%{REQUEST_URI} [L]