Charlie Andrews
Charlie Andrews

Reputation: 1477

Linking to an AngularJS site not at root

I have built a site in angular. Everything works great. IF I go to localhost it brings up the homepage just fine. I can click on a link and it will take me there just fine, but if I refresh the page when I'm not at the root page or if I try and type in a URL it gives me a 404. I have $locationProvider.html5Mode set to true. How can fix this? I think it would be in httpd.conf in apache but I'm not sure.

Upvotes: 0

Views: 212

Answers (2)

Karen Zilles
Karen Zilles

Reputation: 7671

This article gives a good description of the problem:

http://www.josscrowcroft.com/2012/code/htaccess-for-html5-history-pushstate-url-routing/

It suggests adding this to your .htaccess file ( you could also add it directly to your apache conf). You must have mod_rewrite loaded into apache.

# html5 pushstate (history) support:
<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) index.html [L]
</ifModule>

Upvotes: 0

Ven
Ven

Reputation: 19040

Use the <base href="/" /> tag

Upvotes: 1

Related Questions