2017-01-23 48 views
2

我在Angularjs上爲我的單頁應用程序使用HTML5 URL。我通過互聯網上的htaccess代碼將像localhost/project/page這樣的url導向index.php。如果當像localhost/project/page/user這樣的URL發生時刷新頁面,控制檯似乎位於localhost/project/page目錄中,我的代碼看起來不起作用。使用htaccess指向父目錄

截圖: enter image description here (項目文件sosyalmedya)

我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

你頭上有基本元素嗎?

<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 
+0

我有一個index.php的基本href; 。我忘了我添加了這個代碼:) –

+0

你有基本元素嗎? – Daniel

+0

刪除localhost,把它像這樣 Daniel

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) 
+0

結果是一樣的:( –

+0

當在url中有兩個目錄時,它會進入一個不存在的目錄我覺得問題出在htaccess –

+0

檢查緩存 – Daniel