1

I have an apache server running on CentOs and I would like deploy my Angular4 project on this server. This project is deploy in /var/www/html folder. It works weel, except the routing part. When I refresh or access to different URL from the basic index.html, I have a 404 error.

I followed this link : https://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml but nothing change.

My .htaccess :

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html

Part of my /etc/httpd/conf/httpd.conf file :

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

The 404 error is always here. I don't know how i can fix this problem. Did i do something wrong ? Thanks in advance

2 Answers 2

3

It's working with this .htaccess in root :

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^ index.html [L]
</IfModule>
Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure if your rewrite configuration is correct or not (don't know much about Apache configuration).

All i know is that you need to redirect the 404 route to index.html. So if there is a special way to redirect only 404 routes you could try to rewrite that.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.