0

My front-end project is based on 1 file: frontend/index.html

It means that every request like /contact, /about, etc should be responded by index.html file.

I was thought I can use these lines in my httpd.conf file with no any conditions:

<VirtualHost *:80>
    DocumentRoot "/var/www/frontend/"
    RewriteEngine On
    RewriteRule . /var/www/frontend/index.html
</VirtualHost>

But I understood that any existing files (such as frontend/js/app.js or frontend/favicon.ico etc) will also be responded by the index.html while they exist in real directories.

This is what I need:

Request: /contact -> No frontend/contact file -> Response: index.html

Request: / -> No file requested -> Response: index.html

Request: /js/app.js -> frontend/js/app.js exists -> Response: frontend/js/app.js

etc.

What can I write in httpd.conf file in above block to do such thing?

NOTE: I used VirtualHost because I need the back-end files in another port (:8080) of server requests.

1
  • Just use "FallbackResource /index.html" Oct 21 at 21:03

1 Answer 1

0

You could add RewriteCond %{REQUEST_FILENAME} !-f before the rewrite rule or just map /var/www/frontend/index.html as the 404 handler (but you need to override the 404 response with a 200).

1
  • I used RewriteCond clause. but nothing changed. I can map index.html as the 404 handler, but how can I override 404 with 200?
    – MHSarmadi
    Oct 17 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .