3

After removing the hashbang from my routes using

$locationProvider.html5Mode(true);

Now when visiting a page, for example "domain.com/download", it will work. But if I reloaded this exact page, it would give me an 404 Error. Links like "domain.com/download" can only be opened by typing "domain.com/#!/download". Once it loads it would redirect me to the normal "domain.com/download" page again.

Im using v1.3.2 for routing and v1.6.3 for the rest (dont ask me why I didnt make this site lol).

  • 2
    you need to configure your routing (in `.htaccess`) – Aleksey Solovey Aug 15 '18 at 14:57
  • Is that usual? Because I didn't have to do this to make the hashbangs themselves working. – Konstantin Schlegel Aug 15 '18 at 15:01
  • Yes, it is usual, because you need to do this to make URLs *without* a hashbang work. (Your angular app is actually at the path "/"; the hash part of the URL is ignored when determining he path, so "/#!/whatever" still points to "/". "/download" points to a different path, by default, which is not your app; so you need to reconfigure your webserver to point all urls at the same path, where Angular can figure out what to do with it from there.) – Daniel Beck Aug 15 '18 at 15:11

1 Answers1

2

This is what the AngularJS Documentation says:

Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html). Requiring a tag is also important for this case, as it allows AngularJS to differentiate between the part of the url that is the application base and the path that should be handled by the application.

You'll have to change your .htaccess to something like:

RewriteEngine On 
Options FollowSymLinks

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52