Skip to content

Problem with routing builded Angular 6 app and Apache2 #12388

@bakritarek

Description

@bakritarek

Feature Request

Command
build (library)

Versions

Angular CLI: 6.2.3
Node: 8.12.0
OS: Ubuntu LTS
Angular: 6.1.8
Npm: 6.4.1

Desired functionality

I build an Angular 6 application with ng build --prod, and I put the dist folder in a Ubuntu Server with Apache2

In the first I had a problem with routing, when I try to access to an url I had a 404 error and I fixed that with changing my VirtualHost in site-avaible (apache2 directory)

DocumentRoute /var/www/html/
ErrorDocument 404 /folder/index.html

I think it will be possible also with .htaccess file but I tried to put it directly in the same folder as index.html /var/www/html/folder/.htaccess with this content :

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 

But nothing is happening So until this part every thing is working perfect, BUT I realized that I have an other problem when I add an other angular dis folder (for an other project) when I try to access to the second application it redirect me to the first application

I need to know there is a solution in apache2 create an other VirtualHost or I don't know or if there is other solution (out of apache) in angular for exemple who avoid me this kind of problem

Usage context

ng build --prod

Any other details that might be useful

PS : I don't want to work with hash routing Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions