Angularjs Apache Rewrite Rule for HTML5Mode


Posted by Jason Hardin on June 11, 2014

I found that as I was working on an Angularjs project that if you are not using Nodejs there are some rules you need to create to use Angularjs’s html5mode. For Apache you need to add the following rewrite rule to a .htaccess file or virtualhost.

1
2
3
4
5
6
7
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</IfModule>

I credit this to Joss Crowcroft with his post that I found on stackoverflow.