0

I built a VUE CLI Web App Containing Vue-Router and so I should rewrite all requests to index.html file like this:

RewriteEngine On
RewriteRule ^(.*)$ ./index.html [L]

But there is a problem that there are two folders css and js containing packed css's and js's, automaticly generated by Vue-CLI. And the browser will send a request like: https://example.com/css/xyz.css but as rewrited above, the Apache gonna answer index.html file. such for js folder/files

What can I do for Rewrite all Requests to index.html BUT existing files/folders like favicon.ico or Bootstrap css/js files or pictures or css/js files in same folders?

1

1 Answer 1

0

As I read the first comment of the question (Here), I understood that I can use this expression of RewriteCond (Conditioning before Rewriting)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . ./index.html

There are two condtions before rewriting all requests to index.html file, cheking REQUEST_FILENAME that makes sure that REQUEST_FILENAME is not (!) a file (-f) or directory (-d) in the current folder or in one of the subfolders of current folder

Note: Every RewriteCond before ONE RewriteRule only effects the same RewriteRule and does NOT effect any RewriteRule after that RewriteRule

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

3 Comments

With this you would need to make sure that DirectoryIndex index.html is also set (it usually is by default) otherwise requests to the root directory itself are not rewritten to index.html. And ./index.html should be simply index.html (the ./ eventually gets parsed away). However, if your statics assets are in a known set of subdirectories (as would seem to be implied in the question), then it would be more efficient to exclude these subdirectories, rather than perform filesystem checks on every request.
as you know I need to access my files!
and I didn't understand what did you say...

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.