2

When loading a page using Angular an Apache myserver.com everything works fine, when going to a subroute from the main page myserver.com/credits by clicking a link it'll work as well.

However, if I try to go directly to myserver.com/credits from the browser navigation bar it'll return a 404 error message:

Error Message

I'm aware that by working with node I can configure this so that it does work, however, my company website runs in an apache server which I have no access to.

I could make it so the server redirects to the main page myserver.com like so:

.htaccess

ErrorDocument 404 /index.html 

However the optimal resolution would be that going to myserver.com/credits works outright.

Is there a way to make Apache behave this way? And if so, how?

Maxime Pacary
  • 22,336
  • 11
  • 85
  • 113
Erick
  • 2,488
  • 6
  • 29
  • 43
  • 1
    When using angularjs in html5 mode, you need an htaccess that rewrites requests to folders that don't exist back to your index.html so that angular can route it. http://stackoverflow.com/questions/22739455/htaccess-redirect-for-angular-routes – Kevin B Jan 16 '15 at 20:03
  • How would I go about doing that? Just directing me to a link would be enough. Otherwise if you can cover it as an answer I'll accept it. – Erick Jan 16 '15 at 20:05
  • Thanks, flagged this question as a duplicate. https://stackoverflow.com/questions/22739455/htaccess-redirect-for-angular-routes works perfectly. – Erick Jan 16 '15 at 20:09

2 Answers2

2

The answer that solves this question can be found here:

https://stackoverflow.com/a/22740184/1224232

I have flagged this question as a duplicate. I have tested it and it works perfectly.

Special thanks to Kevin B for directing me to the answer, and to Rajasaur for providing the answer.

Community
  • 1
  • 1
Erick
  • 2,488
  • 6
  • 29
  • 43
1

Created a .htaccess file in root directory if not exist. then add the following code in it

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# not rewrite css, js and images
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /index.html?path=$1 [NC,L,QSA]
Taranjeet Singh
  • 147
  • 1
  • 5