我在Angularjs上使用HTML5网址作为单页面应用程序。我使用在互联网上找到的htaccess代码将像localhost / project / page这样的网址引导到index.php。如果我在像localhost / project / page / user这样的url时刷新页面,控制台似乎在localhost / project / page目录中,我的代码看起来但不起作用。
我的htaccess代码;
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.php [L]
我的角度代码;
app.config(["$routeProvider","$locationProvider",function($routeProvider,$locationProvider){
$routeProvider.
when('/', {
templateUrl:'interpages/home.php'
}).
when('/home', {
templateUrl:'interpages/home.php'
}).
when('/notifications', {
templateUrl:'interpages/notifications.php'
}).
when('/messages', {
templateUrl:'interpages/messages.php'
}).
when('/search', {
templateUrl:'interpages/search.php'
}).
when('/profile', {
templateUrl:'interpages/profile.php'
}).
when('/profile/:user', {
templateUrl:'interpages/profile.php'
})
.otherwise({rediectTo:"/home"});
$locationProvider.hashPrefix('!');
$locationProvider.html5Mode(true)
}])
我该如何解决这个问题?我提前感谢您的帮助。
答案 0 :(得分:0)
你有基本元素吗?
<base href="/sosyalmedya/">
试试这个.htaccess:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /sosyalmedya/index.php
答案 1 :(得分:0)
例如
$routeProvider.
when('/', {
templateUrl:'/sosyalmedya/interpages/home.php'
}).
when('/home', {
templateUrl:'/sosyalmedya/interpages/home.php'
}).
when('/notifications', {
templateUrl:'/sosyalmedya/interpages/notifications.php'
}).
when('/messages', {
templateUrl:'/sosyalmedya/interpages/messages.php'
}).
when('/search', {
templateUrl:'/sosyalmedya/interpages/search.php'
}).
when('/profile', {
templateUrl:'/sosyalmedya/interpages/profile.php'
}).
when('/profile/:user', {
templateUrl:'/sosyalmedya/interpages/profile.php'
})
.otherwise({rediectTo:"/home"});
$locationProvider.hashPrefix('!');
$locationProvider.html5Mode(true)