Search code examples
angulardeploymentcpanel

Getting 404 error for an angular application deployed on cPanel when I try to access a specific page using route shared in mail. How can I solve this?


I have created an Angular application and it is working fine. If I try to access a specific page on the browser I can type the route and it will redirect me there. Now the backend shares this route in mail and I would like to redirect to this page.

Accessing the page however, throws 404 error.

I am using cPanel as my hosting service.

Any help would really appreciate. Been trying it for days now.

I have tried changing .htaccess to have RewriteEngine On but still not working as expected.


Solution

  • Check your Nginx configuration file. It should be similar to:

    server{
        listen 80;
        listen [::] 80;
        server_name www.example.com example.com;
        root /var/www/example.com;
        index index.html;
        location / {
            try_files $uri$args $uri$args/ /index.html;
        }
    }
    

    Updated:

    I have never tried that, but something similar to nginx config above but for .htaccess is:

        <IfModule mod_rewrite.c>
          RewriteEngine on
          RewriteCond %{REQUEST_FILENAME} -s [OR]
          RewriteCond %{REQUEST_FILENAME} -l [OR]
          RewriteCond %{REQUEST_FILENAME} -d
          RewriteRule ^.*$ - [NC,L]
          RewriteRule ^(.*) /index.html [NC,L]
       </IfModule>