9 Mart 2019 Cumartesi

Angular Routing Problem on Linux Host

If your angular application working well on localhost then does not work on linux host when redirecting any of existing page with returning 404 error. It means that you have missing routing configuration for routing.

To provide right configuration on linux apache server just put following code to .htAccess file of your angular application root folder and check the the magic :)

.htaccess file content should be as following:
RewriteEngine On # If an existing asset or directory is requested go to it as it is RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html RewriteRule ^ /index.html

On the otherhand, If you deployed your app to another servers check the following solutions :

IIS Server on windows host , following webconfig rule can be help you to solve your redirection problem

web.config file content should be as following;

  1. <system.webServer>
  2. <rewrite>
  3. <rules>
  4. <rule name="Angular Routes" stopProcessing="true">
  5. <match url=".*" />
  6. <conditions logicalGrouping="MatchAll">
  7. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  8. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  9. </conditions>
  10. <action type="Rewrite" url="/index.html" />
  11. </rule>
  12. </rules>
  13. </rewrite>
  14. </system.webServer>

For more information about this issue, just check the offical page from this link : https://angular.io/guide/deployment