Is there a way to rewrite all urls in .htaccess to index.html but existing folders? When I use Vue-Router
P粉425119739
P粉425119739 2023-08-31 23:59:45
0
1
539
<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>
P粉425119739
P粉425119739

reply all(1)
P粉763748806

When I read the first comment of the question (here), I understood that I could use this expression of RewriteCond (conditional handling before rewriting)

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

Before rewriting all requests to the index.html file, there are two conditions, check REQUEST_FILENAME to make sure REQUEST_FILENAME is not (REQUEST_FILENAME >!) A file (-f) or directory (-d)

in the current folder or one of the subfolders of the current folder

Note: ONE RewriteRule Each preceding RewriteCond only affects the same RewriteRule and will not Affects any RewriteRule that follows RewriteRule

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template