2015-04-17 83 views
4

我在我的角度应用程序中使用路由来加载网址。这工作完全当我点击来自应用程序内的链接,但是当我尝试直接到一个应用程序的URL,服务器返回404使用WordPress的角度HTML5模式,刷新页面导致404

这里是我的代码:

myApp.config(function ($routeProvider, $locationProvider) { 
    $locationProvider.html5Mode(true); 

    $routeProvider 
     .when('/booking', { 
      templateUrl: 'wp-content/themes/myapp/pages/begin.html', 
      controller: 'mainController' 
     }) 
     .otherwise({ 
      redirectTo: "/" 
     }); 
}); 

我的头有<base href="/myapp/">在顶部,在头部标签内。

我已阅读,这是一个Apache重写的问题,所以我想修改我的.htaccess包括以下内容:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /myapp/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /myapp/index.php [L] 
</IfModule> 

然而,这似乎并没有发挥作用以外重定向到404页。我正在使用WAMP和localhost。

如何使它刷新应用程序或直接链接到页面将工作?

+0

服务器必须发送到客户端的index.html(或PHP)到underneith网址,(不定向),除非数据文件是存在的。 – YOU

+0

一些类似的帖子 - http://stackoverflow.com/questions/28224012/angular-js-routes-not-working-on-wamp – YOU

回答

0

试试这个

$routeProvider 
    .when('/', { 
    templateUrl: 'wp-content/themes/myapp/pages/index.html', 
    controller: 'indexController' 
    }) 
.when('/booking', { 
     templateUrl: 'wp-content/themes/myapp/pages/begin.html', 
     controller: 'mainController' 
    }) 
    .otherwise({ 
     redirectTo: "/" 
    }); 
0

你有没有改变你的WP的永久链接?

在我的情况改变设置的固定链接到

/blog/%postname%/ 

/%postname%/ 

固定它。

此外,请务必在index.*文件的<head>部分的顶部声明您的base href。我建议使用这个脚本:

<base href="<?php $url_info = parse_url(home_url()); echo trailingslashit($url_info['path']); ?>">