CodeTzu
CodeTzu

Reputation: 65

Angular routing on apache is returning File not Found

I'm using the PathLocationStrategy and deployed my angular14 application on apache. My angular application files are inside the folder "test", which is inside the folder "public_html".

so folder path looks like this: /var/www/game_sites/public_html/test

I have changed the .htaccess file that is inside the "public_html" and I'm still getting File Not found.

My base ref looks like so:

<base href="/teste/">

Rewrite Rule in .htaccess file.

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

What am i doing wrong please? I'm guessing maybe the ReWrite rule is wrong?

I have tried updating the rewrite rule and changed to useHash but to no avail

Upvotes: 1

Views: 832

Answers (1)

MrWhite
MrWhite

Reputation: 45958

RewriteRule ^/index.html

You are missing a space between the RewriteRule arguments.

However, if all your files are in the /test subdirectory (including index.html) and /test is present in the URL then the .htaccess file should also be in the /test subdirectory, not the document root. It should then look like this:

# /test/.htaccess

DirectoryIndex index.html

RewriteEngine On

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

Note there is no slash before index.html in the RewriteRule substitution.

The relative substitution string is relative to the directory that contains the .htaccess file. Likewise, the URL-path that is matched by the RewriteRule pattern is also relative to the directory that contains the .htaccess file.

The first rule is just an optimisation and will work without it.

Upvotes: 2

Related Questions