问题描述
我正在尝试使用 AngularJS 设置 apache 2.2,其结构几乎与以下封闭问题中的结构完全相同.
I am trying to setup apache 2.2 with AngularJS with an almost exact structure as the one from the following closed question.
我想将所有请求重定向到 app/index.html,除了对/api 的请求.
I would like to redirect all requests to app/index.html except for requests to /api.
我的目录结构如下
- /
- /应用
- /app/index.html
- /app/css
- /app/js
- /api
我正在尝试在 httpd-vhosts 文件中应用这些重定向规则,该文件已作为正确答案发布https://stackoverflow.com/a/15284848/671095 到问题.
I am trying to apply these redirect rules in the httpd-vhosts file as such which was posted as the correct answer https://stackoverflow.com/a/15284848/671095 to the question.
<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.或 js 并返回 404.
However when I try visit / in the browser I am presented with a blank screen. If I enter to /app/index.html in the browser however I am able to view the html page in my browser but none of the css.or js can be accessed and is returning a 404.
我一直对这个很着迷,这似乎是作为 apache 重写来完成的一件简单的事情.
I have been going nuts over this which seems like a simple thing to accomplish as an apache rewrite.
任何帮助将不胜感激
推荐答案
这在 Apache 2.2.16+ 中使用 FallbackResource 指令变得更加容易.
This is now much easier in Apache 2.2.16+ using the FallbackResource directive.
FallbackResource /app/index.html
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource
根据您转发对 API 的访问的方式,您可能还需要利用外壳来禁用专门针对 API 请求 (2.2.24+) 的回退资源.
Depending on how you're forwarding access to your API you may need to also leverage the enclosure to disable the fallback resource on specifically on API requests (2.2.24+).
<Directory /api>
FallbackResource disabled
</Directory>
这篇关于Apache 重写规则未应用于 angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!