0

I made a small angular2 route app. It is working fine while 'npm start'.

But as soon as I deploy it to apache, whenever I try to change route manually by typing in browser address bar, it shows error.

I tried solution given at Angular2 routing / deep linking not working with Apache 404 , but it is still not working while changing route manually.

I made a small screencast of my problem. If anyone can help me. https://youtu.be/a7oDW3KsYCU

Thanks

[EDIT] My .htaccess is

<IfModule mod_rewrite.c>
  Options Indexes FollowSymLinks
  RewriteEngine On
  RewriteBase /angulardeploy2/
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

How can I modify it.

Community
  • 1
  • 1
raju
  • 6,448
  • 24
  • 80
  • 163

1 Answers1

0

This setting in src/.htaccess should work, provided that mod_rewrite is enabled.

RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

and do not forget to include .htaccess file in the bundle that gets deployed , you can do that by registering the file as an asset in .angular-cli.json.

 "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico",
        ".htaccess"
      ],