Angular & Apache url rewriting

Zahid Rasheed
May 1, 2021

If your are deploying your angular app on an apache server, you might end up on this screen if you manually refresh your app.

To fix this, you can follow following steps:

1- Enable URL Rewriting:

In order to use mod_rewrite, shh into your ubuntu server and type following commands in the terminal:

~ sudo a2enmod rewrite
~ sudo systemctl restart apache2

2- Create .htaccess file in the root of your deployed project:

~ nano .htaccess

3- Paste the following code in the newly created file:

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

Save the file and your problem should be fixed now :)

--

--

Zahid Rasheed

A human. Being, Technology Freak, Sun hater; snow lover, Enjoys Photography, Live to Travel and Trying to be a better human being everyday.. http://zahid.cc