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).

3
  • 2
    you need to configure your routing (in .htaccess) Commented Aug 15, 2018 at 14:57
  • Is that usual? Because I didn't have to do this to make the hashbangs themselves working. Commented Aug 15, 2018 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.) Commented Aug 15, 2018 at 15:11

1 Answer 1

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] 
Sign up to request clarification or add additional context in comments.

3 Comments

(This answer assumes they're using apache as the webserver; other webservers will need different configuration. note also minor typo on .htaccess)
Fixed the typo. Yup this assumes apache though you can lookup what you'd need for other configurations pretty easily.
This worked, thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.