Javascript 仍然得到';未找到';使用angular.js route手动刷新时
在Angular.js route上阅读了大量的评论和stackoverflow问题之后,当我进行手动刷新时,仍然会出现“找不到”错误 步骤:Javascript 仍然得到';未找到';使用angular.js route手动刷新时,javascript,.htaccess,angularjs,angular-routing,Javascript,.htaccess,Angularjs,Angular Routing,在Angular.js route上阅读了大量的评论和stackoverflow问题之后,当我进行手动刷新时,仍然会出现“找不到”错误 步骤: 浏览到localhost-->由于我的配置(如下),我被带到localhost/home。视图和所有内容都很好 在浏览器-->浏览器中点击“刷新”按钮,会显示以下信息:未找到:在此服务器上未找到请求的/home 这个问题可能最像 我的配置 //路由配置。 angular.module('myModule') .config(['$routeProvide
localhost
-->由于我的配置(如下),我被带到localhost/home
。视图和所有内容都很好未找到:在此服务器上未找到请求的/home
//路由配置。
angular.module('myModule')
.config(['$routeProvider','$locationProvider',
函数($routeProvider,$locationProvider){
//在管线中启用pushState。
$locationProvider.html5Mode(true);
$routeProvider
.when(“/home”{
模板:{
布局:'/views/home.html'
},
标题:“欢迎!”
})
.when(“/launchpad”{
模板:{
布局:'/views/layouts/default.html',
内容:'/views/partials/profile.html'
},
标题:“启动板”
})
.否则({
重定向到:'/home'
});
}
]);
我做过的其他事情:
- 在我的
中,我已经有了index.html
- 升级到angular 1.2.1
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}!指数
重写条件%{REQUEST\u URI}!。*\。(css | js | html | png)#添加所需的额外扩展。
重写规则(.*)index.html[L]
从
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)/index.html/#/$1.
我不知道这是否是最佳解决方案,但我确实找到了一个有效的设置组合:
- 包括
(见下文)哈希前缀(“!”)
- 未在my index.html中包含
- 根据将
添加到我的服务器FallbackResource/index.html
文件的.conf
部分。设置此项后,本地
设置是什么似乎并不重要mod_rewrite
//路由配置。
angular.module('myModule')
.config(['$routeProvider','$locationProvider',
函数($routeProvider,$locationProvider){
//在管线中启用pushState。
$locationProvider.html5Mode(true).hashPrefix(“!”);
$routeProvider
.when(“/home”{
模板:{
布局:'/views/home.html'
},
标题:“欢迎!”
})
.when(“/launchpad”{
模板:{
布局:'/views/layouts/default.html',
内容:'/views/partials/profile.html'
},
标题:“启动板”
})
.否则({
重定向到:'/home'
});
}
]);
这个.htaccess设置对我来说很好
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule (.*) /#!/$1 [NE,L,R=301]
</IfModule>
选项+FollowSymlinks
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_URI}^/$
重写规则(.*)/#/$1[NE,L,R=301]
对于仍面临此错误的人员,无论是否使用SSL:
确保您允许在您的apacheconfig中超车,例如
<Directory "/var/www/mysite/public_html">
AllowOverride All
</Directory>
允许超越所有
对于这两个端口,您都可以使用SSL我无法评论,但也可以使用
HTML模式
,base href=“/”
,sudo a2enmod rewrite
,使用.htaccess
rewrite。从Unispaw开始,我必须允许您在和/etc/apache2 apache.conf
两个站点中覆盖所有可用的,和重写规则^(.*)$index\.html#/$1[L]
(点是保留字符,因此应该转义它)?你确定修改后的代码能正常工作吗?很难判断错误在哪里,所以我会检查所有内容。是的,我后来发现hashPrefix
是工作组合的一部分(请参见答案)。我相信,mod_rewrite
能够工作,因为我能够从中获得日志输出:(在RewriteLog MY_log\u PATH RewriteLogLevel 3上使用blockRewriteEngine)。我尝试了重写规则和两个重写秒(!-f
和!-d
)但对我无效。嘿,你找到解决办法了吗??我可以在hashbang模式下刷新,但在html5模式下,它仍然显示未找到的对象。如果您有任何解决方案,请告诉我
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule (.*) /#!/$1 [NE,L,R=301]
</IfModule>
<Directory "/var/www/mysite/public_html">
AllowOverride All
</Directory>