我使用$locationProvider
从此hashtag #
url
http://localhost/angular-phonecat/app/#/phones
使用以下代码:
phonecatApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/phones', {templateUrl: 'partials/phone-list.html', controller: 'PhoneListCtrl'}).
when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: 'PhoneDetailCtrl'}).
otherwise({redirectTo: '/phones'});
$locationProvider.html5Mode(true);
}]);
并在index.html
中添加了这个
<base href="/angular-phonecat/app/">
这有效,我现在的网址是:
http://localhost/angular-phonecat/app/phones
但是当我直接访问此url
时,它没有显示网页,因为它没有调用index.html
文件。相反,它显示/app/phones
目录
我尝试创建.htaccess
文件
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.html [L]
答案 0 :(得分:1)
规则中存在一个小错误,重写规则需要多一个参数。
此外,当您编写RewriteCond %{REQUEST_FILENAME} !-d
时,如果存在具有此名称的目录,则会阻止重定向。由于存在/anular-phonecat/app/phones
,您还需要删除此行。
您不需要RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
条件,因为RewriteCond %{REQUEST_FILENAME} !-f
条件无法重定向文件
结果是:
RewriteEngine On
RewriteBase /angular-phonecat/app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.html [L]
根据评论编辑的回复