search

Home  >  Q&A  >  body text

Is there a way to rewrite all urls in .htaccess to index.html but existing folders? When I use Vue-Router

<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粉425119739P粉425119739459 days ago541

reply all(1)I'll reply

  • P粉763748806

    P粉7637488062023-09-01 09:04:12

    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

    reply
    0
  • Cancelreply