• GoDaddy Community
  • VPS & Dedicated Servers
  • VPS & Dedicated Servers

    cancel
    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Go to solution

    Using Angular 2 routing on Linux Hosting with cPanel

    I'm able to upload and run my Angular 2 app, but when refreshing a page with routing, I get a 404 error.  Is it possible to change redirects, the 404 page, or another setting to enable Angular 2 routing to work?  Thanks.

    6 REPLIES 6
    Advocate II Advocate II
    Advocate II

    Re: Using Angular 2 routing on Linux Hosting with cPanel

    If you are able to add rewrites to htaccess, it's easily solved. Not in a position right now to give you examples, maybe tomorrow. Do you have access to .htaccess?
    Mike Kikkert | GD Reseller | Javascript specialist | SSL/Security and performance specialist.

    Re: Using Angular 2 routing on Linux Hosting with cPanel

    Yes, I have access to .htaccess.  Thanks for the quick response.  I'll do some research with that.

    Solution

    Re: Using Angular 2 routing on Linux Hosting with cPanel

    Okay, I think I got it.  I added an .htaccess file in the same directory as my Angular app.  The contents of the file:

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

    Seems to be working so far.  Thanks for the push in the right direction, @MikeOne.

    New

    Issue on hosting Angular 2 App

    I'm not able to host my angular 2 app on windows hosting . I've done all steps that are required to publish an angular app but still no breakthrough. It shows ' 500 - Internal server error'

    Re: Using Angular 2 routing on Linux Hosting with cPanel

    Ok. this config work in my page. Nice solution.

    New

    Re: Using Angular 2 routing on Linux Hosting with cPanel

    Nice solution thanks