1

I use angular.js and slim framework for api. My directory structure is

root/
   api/
   frontend/
   .htaccess

In root directory I have .htaccess file

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/frontend/$1 !-d [NC]
RewriteCond %{DOCUMENT_ROOT}/frontend/$1 !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /frontend/index.html [L]

RewriteCond %{DOCUMENT_ROOT}/frontend/$1 -d [NC,OR]
RewriteCond %{DOCUMENT_ROOT}/frontend/$1 -f
RewriteCond %{REQUEST_URI} !^/frontend/ [NC]
RewriteRule ^(.*)$ /frontend/$1 [L]

It work ok but when I try to get file that doesn't exists apache returns content of index.html and status 200 OK instead of 404 so code like this

<script src="/thisFileDoesntExists.js"></script>

will return content of index.html. How to retun 404 for wrong files?

1 Answer 1

1

Your first rule is the culprit which is sending all non-files/directories to index.html. Remove it with a DirectoryIndex on top:

DirectoryIndex index.html
Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/frontend/$1 -d [NC,OR]
RewriteCond %{DOCUMENT_ROOT}/frontend/$1 -f [NC]
RewriteRule ^((?!frontend/).*)$ frontend/$1 [L]
Sign up to request clarification or add additional context in comments.

Comments

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.