Skip to content

Instantly share code, notes, and snippets.

@jbutko
Created September 9, 2014 07:19
Show Gist options
  • Save jbutko/6b500210b4c6811bca54 to your computer and use it in GitHub Desktop.
Save jbutko/6b500210b4c6811bca54 to your computer and use it in GitHub Desktop.
.htaccess, #AngularJS, UI-Router: Configure Apache server to work with html5Mode
# this ensures support for pretty links even after page refresh (F5)
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</IfModule>
# via https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode
@yves-s
Copy link

yves-s commented Feb 1, 2015

I don't get it. I don't get a redirected.

If I got to an Frontend routed page like "https://mypage.com/#/whatever" I get a nicely and cleaned URL. After refreshing my Browser with that cleaned URL like "https://mypage.com/whatever" I get an 404. So the server doesn't find the file or directory.

Any Idea what could go wrong and why I don't get redirected to the index.html?

@jlmayoral
Copy link

"to work with html5Mode"!!

/ it's not.

Yes very fine.. work well
Perfect!!
Thanks

@jamespsterling
Copy link

Exactly what I needed, thanks!

@devner007
Copy link

devner007 commented May 11, 2016

What would be the href values for the links to navigate? For example, please consider the following links:
<a href="1">Home</a> | <a href="2">Members</a> | <a href="2/3">Child of Members</a>
In the above, what would be the values of 1, 2 and 3? The first link points to Home page, 2nd link points to Members page, 3rd link points to the child present inside the Members page (folder)?

Any help is appreciated.

@robinw77
Copy link

@yves-s: Did you solve this? I'm getting the same problem

@cullsin
Copy link

cullsin commented May 14, 2016

Hello,

I am also getting the same problem. If I refresh http://anaoh.com/home, It shows the directory index.
Please let me know if you have any suggestion.

Raja K

@maphi88
Copy link

maphi88 commented May 25, 2016

Need Help!!
On refreshing pages " localhost/blog/list " or opening pages "localhost/blog/" does not work while links like "localhost/blog" open even on refreshing.

@jml6m
Copy link

jml6m commented Jul 6, 2016

To those still facing this problem, it's more common now to use the FallbackResource directive instead of adding a mod_rewrite block. Read more here.

@devsubhajit
Copy link

devsubhajit commented Mar 22, 2018

This works perfectly, but in child routing, it throughs errors,
"Uncaught SyntaxError: Unexpected token"
and page doesn't get loaded.

Need help on this

@ReverseLogicSocial
Copy link

I am also having the same problem.
Ever since I turned on the html5 mode, all emails links and forced browser reloads are breaking.
Any help how to overcome this scenario?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment