[英]Apache Rewrite Excluding Assets Directory
我正在編寫一個微型MVC應用程序。 應用架構:
動作/模板/網站/應用/樣式/圖片/腳本/
到目前為止,我已經使控制器正常工作,可以接受所有請求。 但是,JavaScript文件無法在瀏覽器中正確呈現; 嘗試在瀏覽器中加載文件時出現404未找到。
這是我當前在vhost文件中的目錄配置:
<Directory "/path/to/apps/ecatalogue">
DirectoryIndex index.php
RewriteEngine On
RewriteBase /apps/ecatalogue
RewriteRule ^scripts/(.*) - [NC,L] <--- Rule not working
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,L,QSA]
</Directory>
我可以確認其他所有方法都可以; 我只需要Apache即可忽略腳本中的任何內容,因此可以正常加載文件而無需由控制器處理。
感謝您的幫助。
更新I:為完成起見添加了目錄標簽。
我在這里切換了幾件事-這是基於我運行的幾乎所有MVC應用程序都使用的重寫規則。 它來自Zend Framework文檔中的一些建議。
DirectoryIndex index.php
RewriteEngine On
RewriteBase /apps/ecatalogue
# If it's a file/directory/symlink, serve it.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
# Otherwise let's go MVC
RewriteRule ^.*$ index.php [NC,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.