我正在尝试使用AngularJS设置apache 2.2,其结构几乎与下面的closures问题完全一样。
重写规则为apache 2使用angularjs
我想将所有请求redirect到app / index.html,除了对/ api的请求。
我的目录结构如下
我试图在httpd-vhosts文件中应用这些redirect规则,因为这是正确的答案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>
但是,当我尝试访问/在浏览器中,我提出了一个空白的屏幕。 如果我在浏览器中input/app/index.html,但是我可以在浏览器中查看html页面,但是没有一个css.or js可以被访问,并且正在返回404。
我已经疯了,这似乎是一个简单的事情来完成作为一个Apache重写。
任何帮助将非常感激
在使用FallbackResource指令的Apache 2.2.16+中,这样做更容易了。
FallbackResource /app/index.html
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource
取决于您如何转发对API的访问,您可能还需要利用机箱禁用专门针对API请求(2.2.24 +)的后备资源。
<Directory /api> FallbackResource disabled </Directory>
这适用于我:
<ifmodulee mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !index RewriteRule (.*) index.html [L] </ifmodulee>
我有同样的问题。 但是我对mod_rewrite
一无所知,所以不得不去谷歌。 我在这封邮件中找到了解决方案:
https://groups.google.com/d/msg/angular/GmNiNVyvonk/mmffPbIcnRoJ
所以我认为你的.htaccess应该如下所示:
Options +FollowSymLinks IndexIgnore */* 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 RewriteRule ^.*$ - [NC,L] # otherwise forward it to index.html RewriteRule ^app/(.*) /app/#/$1 [NC,L]
注意(.*)
和#/$1
注意:你必须在你的包含CSS,JS等中使用绝对路径,否则你会得到错误:
资源解释为脚本,但与MIME类型文本/ HTML传输
不知道你是否还有这个问题,但是我和AngularJS和Apache 2有相同的症状。
我的问题实际上是我使用IE浏览器,它自动出现在兼容模式。 我在我的HTML中使用下面的行,它的工作。
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
在这里进一步描述:< meta http-equiv =“X-UA-Compatible”content =“IE = edge”>是做什么的? >。