简体   繁体   中英

Angular4 deploy server apache route

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

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM