【发布时间】:2014-06-28 16:52:24
【问题描述】:
我正在使用 Yeoman 包管理器来创建一个 Angular Web 应用程序。这是我的主控制器:
'use strict';
angular
.module('resFourApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.when('/contact', {
templateUrl: 'views/contact.html',
controller: 'ContactCtrl'
})
.otherwise({ redirectTo: '/' });
// use the HTML5 History API
// use the HTML5 History API
$locationProvider.html5Mode(true);
});
如果我从基本目录访问应用程序,它工作正常,但如果我从 url 访问它并转到 www.base.com/route,我会收到 404 错误。我的理解是因为 Angular 是一个客户端应用程序,所以服务器上没有任何东西可以处理这些请求。我在网上阅读了很多关于必须使用服务器重新路由或使用 apache 重写 mod,但我仍然没有让它工作。
我尝试过的事情
Apache rewrite rules not being applied for angularjs
https://groups.google.com/forum/#!msg/angular/GmNiNVyvonk/mmffPbIcnRoJ
我的 .htaccess 用于 apache 网络服务器:
# BEGIN angularJS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.html/#/$1
</IfModule>
# END angularJS
【问题讨论】:
标签: angularjs apache .htaccess mod-rewrite