I am using routing in my angular app to load urls. This works perfectly when I click links from inside the app, but when I try to go directly to an app url, the server returns a 404.
Here is my code:
myApp.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/booking', {
templateUrl: 'wp-content/themes/myapp/pages/begin.html',
controller: 'mainController'
})
.otherwise({
redirectTo: "/"
});
});
My header has <base href="/myapp/">
at the top, within the head tags.
I have read that this is an apache rewrite issue, so I tried modifying my .htaccess to include the following:
<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>
However, this does not seem to make a difference other than redirecting to the 404 page. I am using WAMP and localhost.
How do I make it so that refreshing the app or linking directly to the page will work?
Try this
Did you changed your WP permalinks?
In my case changing the Permalinks Settings to
or
fixed it.
Also, please make sure to declare your
base href
at the top of the<head>
section in yourindex.*
file. I recommend using this script:<base href="<?php $url_info = parse_url( home_url() ); echo trailingslashit( $url_info['path'] ); ?>">