我想用一個幾乎精確的結構來設置apache 2.2與AngularJS作爲一個從以下封閉的問題。Apache重寫規則不適用於angularjs
rewrite rules for apache 2 to use with angular js
我想重定向所有請求的應用程序/ index.html的,除了請求/ API。
我的目錄結構其次
- /
- /應用
- /app/index.html
- /應用/ CSS
- /應用/ JS
- /API
我正在嘗試在httpd-vhosts文件中應用這些重定向規則,將其作爲問題的正確答案https://stackoverflow.com/a/15284848/671095發佈。
<VirtualHost *:80>
ServerName www.test.com
DocumentRoot "C:/websites/test"
Alias /CFIDE "C:/websites/CFIDE"
RewriteEngine On
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/api
# otherwise forward it to index.html
RewriteRule ^.*$ - [NC,L]
RewriteRule ^app/. /app/index.html [NC,L]
</VirtualHost>
但是,當我嘗試訪問/在瀏覽器中,我提出了一個空白屏幕。如果我在瀏覽器中輸入/app/index.html,但是我可以在瀏覽器中查看html頁面,但是沒有一個css.or js可以訪問並且返回404。堅持這個看起來像一個簡單的事情來完成一個Apache重寫。
任何幫助,將不勝感激
我已經將這些規則應用於httpd-vhosts文件,但是當我嘗試訪問mywebsite.com時,它現在還沒有傳遞給index.html文件,現在當我訪問mywebsite.com/app /'我時在瀏覽器中顯示爲404 – matthew 2013-03-14 23:52:48
我使用了您的代碼,並看到「內部服務器錯誤」消息。有想法該怎麼解決這個嗎? – Devner 2015-10-23 11:02:07