1

I have a PHP page over at mysite.com/somedir/script.php.

When I have <a> tags in my Angular views that point to this script, Angular's routing always brings me back to mysite.com/index.html when I click on them.

This is my $routeProvider configuration:

siteModule.config(function($routeProvider, $locationProvider) {
    $routeProvider
        .when('/', {
            templateUrl:'/views/blog.html',
            controller:'blogController'
        })
        .when('/blog',{
            templateUrl:'/views/blog.html',
            controller:'blogController'
        })
        .when('/work',{
            templateUrl:'/views/work.html',
            controller:'workController'
        });
    // For Pretty URLs
    $locationProvider.html5Mode(true);
});

I'm also using some Apache mod_rewrite to handle 404s / page refreshes in an .htacess file that I think may be interfering:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]

The aforementioned PHP page is a valid (existing) resource so I'm not sure why Angular or Apache would redirect / rewrite away from it. I'm using the target="_blank" on the <a> tags and have the <base href="/"> set in the index page's <head> tag as well.

I just want to be able to access my script normally instead of being pointed back to the index page.

nhuff717
  • 369
  • 2
  • 3
  • 17

1 Answers1

0

In javascript you can still use window.location.href to escape the router, so in the 'otherwise' section of your router, use window.location.href = {the route} instead of allowing it to use the default index.

See these other answers to this question:

Angular routes - redirecting to an external site?

Using $routeProvider to redirect to routes outside of Angular

Community
  • 1
  • 1
Peter Ashwell
  • 4,292
  • 2
  • 18
  • 22