1

I have a angular 9 project. I deployed it to server. On server when I refresh angular app, it shows error :

Error:

start

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

end

we are using below for development

server : Apache

frontend : angular

backend : nodejs

I did not understand what happened. I tried this solution

link to solution what I found

but We don't want # in over url. with out #, we want solution. please suggest proper solution. thanks for your time.

2 Answers2

0

Build your app like this using angular cli.

ng build --prod --base-href /<project_name>/

Try with this in .htaccess one and let me know as It works for me.

Put .htaccess in src folder (final path for is src/.htaccess) and give the file path in angular.json inside "assets"

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

Reference

sibabrat swain
  • 1,277
  • 8
  • 20
0

You need to place a .htaccess file on the root of the deployed project i.e. along with index.html. Below is the code to be written in the above file.

<IfModule mod_rewrite.c>
RewriteEngine on

# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html
# to allow html5 state links
RewriteRule ^ index.html [L]

Please see the below image -

enter image description here

Alok Mali
  • 2,821
  • 2
  • 16
  • 32