2

I am facing one issue related to the angular app, using components in my app then when I go with the single page the page loaded successfully but when I open that URL in a new tab or reload it, give error Not found.

I am using AWS apache server for this and only facing this issue on it, in my Godaddy server page reloading working properly.

Here I am attaching my screenshot of the error.[Error}[1]

Thankx in advance

5
  • You can possibly find the solution from stackoverflow.com/questions/47373927/… . After refresh, ur server is not able to resolve the url as its being generated by angular not the server Commented Mar 31, 2018 at 6:16
  • Thankx for a quick response, Could you please explain more in which file this code will be applied? Commented Mar 31, 2018 at 6:21
  • I think you need to check for config file for apache server. You might need to redirect certain url patterns. I would suggest you to google it out for AWS apache server and update your question with your finding. I'll try to pick it up from there as I am also not much aware of this conf file. Commented Mar 31, 2018 at 6:25
  • angular.io/guide/… Commented Mar 31, 2018 at 6:28
  • @ShashankVivek thanks, I already tried this but not finding a solution. Commented Mar 31, 2018 at 6:32

2 Answers 2

6

I think your .htaccess file is not reachable,

Create .htaccess file inside /var/www/html i.e. in the folder where your index.html is.

Put following code in it:-

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 

Than goto /etc/apache2 folder and open apache2.conf file with sudo.

cd /etc/apache2
sudo vim apache2.conf

Remove comment(#) of AccessFileName it will look like

AccessFileName .htaccess 

Then find the line where there is

<Directory /var/www/>
     Options Indexes FollowSymLinks
     AllowOverride None
     Require all granted
</Directory>

replace "None" with "All"

AllowOverride All

Done!

Now run command

sudo service apache2 restart

And check now!

Sign up to request clarification or add additional context in comments.

1 Comment

In my case, adding of .htaccess file as shown above was enough to prevent site from crashing. So direct server configuration may not be needed (if server is preconfigured, of course).
3

Add .htaccess file in your project root folder. bellow code add in your Appache .htaccess file:

RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

Nginx .conf file :

location / {
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.html break;
  }
}

execute command :

sudo a2enmod rewrite

sudo service apache2 restart

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.