我已經存儲在htaccess重寫循環?
/public/upload/*
例如用戶上傳的文件:
/public/upload/gallery/segway/child-on-a-segway.jpg
我目前的.htaccess規則已經消除/public
部分,但我仍然需要擺脫/upload
部分,但是,僅適用於具有給定擴展名但不包含在其他目錄中的文件,例如js
或img
。我目前的.htaccess看起來像這樣(典型的Zend框架項目):
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
在擺脫/upload
部分工作的希望,我寫這在我的.htaccess的末尾:
RewriteCond %{REQUEST_URI} ^(?<!upload|img|js|less|css)/.*(jpg|mp3|png)$
RewriteRule ^(.*)$ /upload/$1
基本上,如果一個文件具有jpg,png或mp3擴展名,並且它的路徑不以「upload」,「js」,「css」,「img」或「less」開頭,則將前綴「上傳」到請求URI 。那麼,它失敗了。當我在地址欄中輸入:http://example.com/gallery/1/php193A.jpg
,我得到一個303錯誤:
You don't have permission to access /upload//public/upload/public/upload/public/upload/public/upload/public/upload/public/upload/public/upload/public/upload/public/gallery/1/php193A.jpg/1/php193A.jpg/gallery/1/php193A.jpg/1/php193A.jpg/upload/public/gallery/1/php193A.jpg/1/php193A.jpg/gallery/1/php193A.jpg/1/php193A.jpg/upload/public/upload/public/gallery/1/php193A.jpg/1/php193A.jpg/gallery/1/php193A.jpg/1/php193A.jpg/upload/public/gallery/1/php193A.jpg/1/php193A.jpg/gallery/1/php193A.jpg/1/php193A.jpg...
和URL的推移和對幾十行,就好像是循環。
這是我第一次處理.htaccess重寫規則。我會很感激一些幫助他們設置直線,因爲我完全迷失在這裏。提前致謝。
我實際上是在錯誤信息笑了相當困難,ahaha – Cyclone
我的客戶不會覺得太好玩了,雖然:( – mingos
這就是爲什麼我目前正在調試它爲你笑 – Cyclone