我的app.js
app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) {
$routeProvider.
when('/', {
templateUrl: 'interests.html',
controller: 'InterestsController'
})
.when('/interests',{
templateUrl: 'interests.html',
controller: 'InterestsController'
})
.when('/subjects',{
templateUrl: 'subjects.html',
controller: 'SubjectsController'
})
.when('/prequalification',{
templateUrl: 'prequalification.html',
controller: 'PreQualificationController'
})
.when('/qualification',{
templateUrl: 'qualification.html',
controller: 'QualificationController'
})
.when('/personalinfo',{
templateUrl: 'personalinfo.html',
controller: 'PersonalInfoController'
})
.otherwise({
redirectTo : '/interests'
});
if(window.history && window.history.pushState){
$locationProvider.html5Mode(true);
}
}]);
在index.html文件中。 index.html文件的路径:localhost:8080 / cf /。所有其他视图也驻留在index.html
<base href="/cf/">
.htaccess文件内容(.htaccess文件的路径:localhost:8080 / cf / .htaccess)
<ifModule mod_rewrite.c>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ cf/index.html [L]
</ifModule>
服务器上项目文件夹的路径是:localhost:8080 / cf。我在stackoverflow的其他帖子的.htaccess文件中有各种规则,但没有任何工作。甚至当我重新加载或刷新页面时,我得到404.在刷新和重新加载一切都工作正常。请帮忙!!!
答案 0 :(得分:1)
第1步:在app config中添加
if(window.history && window.history.pushState){
$locationProvider.html5Mode(true);
}
第2步:在index.html文件中添加
<base href="/your-app-name">
步骤3:在根目录上添加.htaccess文件
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]
答案 1 :(得分:0)
使用
<base href="/cf">
在文件“head”部分。
希望这会有所帮助!!