Posts

Showing posts from 2015

AngularJS under lighttpd: fixing 404 error in html5Mode

Problem: If you let angularJS use its nice-url $locationProvider.html5Mode(true), you won't be able to normally refresh the page because all the url changing thing goes on the client side.
Solution: The solution is quite simple - use the correct redirections in the lighttpd's rewrite module. For example, you've got four pages in angular stored in subdirectory "/data/" and would like to see them on refresh. Main angular app residing in index.html
Here is what your rewrite rules may look like:
url.rewrite-once = (
"^(/(?!(page1|page2|page3|page4)).*)" => "/data/$1","^(/(page1|page2|page3|page4).*)" => "/data/index.html/#/$1",)

Of course, you can have a totally different setup but the idea is simple - exclude all the pages when requesting static html/js/css and route these pages to main angular app's code via "#".

Solved!