Search code examples
angularjsmodxngrouteroute-providerangularjs-ng-route

Angularjs Routeprovider in MODx subfolder


I've got angularjs app running on MODx website. There is some page with URL like

localhost/www.mysite.com/angularapp/

which contains the app.

URLs inside app look like

localhost/www.mysite.com/angularapp/category/1

base href is set to /www.mysite.com/angularapp/

Everything works fine, but I can not reach the subpages of the app directly.

If I type localhost/www.mysite.com/angularapp/category/1 in address bar, I get to modx start page. But if I go to the link via app - it works.

What did I miss ?

Thanks


Solution

  • You have to exclude the angularapp folder from the default htaccess friendly URL rewrite and add a new rule for this. Include the following line

    RewriteRule ^(angularapp/)(.*)$ index.php?q=$1&r=$2 [L,QSA]
    

    before the friendly URL part. The angular app has to work with $_GET['r'] then.

    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    Edit: changed the htaccess code to the final solution.