I have an Angular app that uses PHP for the API and a little bit for the frontend as well.
Routing has become impossible; only 1st level routes are returned.
My structure is as follows:
- /app/index.html
- /app/scripts/[all angular files]
- /app/views/[all PHP-parsed HTML files]
- /app/api/[app PHP files]
Router (Angular):
angular.module('MyApp')
.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {redirectTo: '/home'})
.when('/home', {
templateUrl: 'views/mainview.php?sec=home',
controller: 'HomeCtrl'
})
.when('/user', {
templateUrl: 'views/mainview.php?sec=user',
controller: 'ProfileCtrl'
});
vhosts Apache file
<VirtualHost 127.0.0.2:80>
DocumentRoot "M:/site/app"
# names and emails commented out
</VirtualHost>
.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/user/([0-9]+)$ /user?user=$1
</IfModule>
When I access 127.0.0.2, it redirects to /home and works fine. When I access /user?id=1, it also works fine. But if I retrieve /user/1, then only the main php-parsed HTML loads, but all dependencies (scripts, css, whatever else) just return the same main HTML file, thus failing.
I have seen many StackOverflow responses and so far I have not been able to fix anything...
Can anyone help me make routing happen?