1

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

2
  • So, presumably /test/ is present in the URL? And the index.html file is located inside the /test subdirectory? <base href="/teste/"> - presumably that should be /test/? But is the base element required to begin with? Commented Nov 2, 2022 at 2:12
  • Yes the index.html file is located inside the /test subdirectory. Thanks for pointing out that typo. I used @MrWhite solution and it works. Thanks Commented Nov 3, 2022 at 21:42

1 Answer 1

2
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.

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

1 Comment

@CodeTzu You're welcome. If this answered your question then please mark it as accepted (grey/green checkmark below the voting arrows) to help other readers. Thanks, much appreciated :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.