Is there a way to rewrite all urls in .htaccess to index.html but existing folders? When I use Vue-Router
P粉425119739
2023-08-31 23:59:45
<p>I built a <code>VUE CLI</code> web application that includes <code>Vue-Router</code>, so I should rewrite all requests to <code>index. html</code> file, as shown below: </p>
<pre class="brush:php;toolbar:false;">RewriteEngine On
RewriteRule ^(.*)$ ./index.html [L]</pre>
<p>But there is a problem, there are two folders <code>css</code> and <code>js</code> containing packaged <code>css</code> and <code> js</code> >, automatically generated by <code>Vue-CLI</code>. The browser would send a request like: <code>https://example.com/css/xyz.css</code>, but as rewritten above, <code>Apache</code> would answer< code>index.html. html</code> file. For example <code>js</code> folder/file</p>
<p>How to rewrite all requests to <code>index.html</code> but existing files/folders like <code>favicon.ico</code> or <code>Bootstrap</ code> <code> css</code>/<code>js</code> files or images or <code>css</code>/<code>js</code> files are in the same folder ? </p>
When I read the first comment of the question (here), I understood that I could use this expression of
RewriteCond
(conditional handling before rewriting)Before rewriting all requests to the
in the current folder or one of the subfolders of the current folderindex.html
file, there are two conditions, checkREQUEST_FILENAME
to make sureREQUEST_FILENAME
is not (REQUEST_FILENAME
>!) A file (-f
) or directory (-d
)Note: ONE
RewriteRule
Each precedingRewriteCond
only affects the sameRewriteRule
and will not Affects anyRewriteRule
that followsRewriteRule