0

I have a simple VueJS site that ive built and im deploying it to an apache server. I am having trouble with the .htaccess rewrite rules.

Right now it throws errors because index.html is looking for the files at the root(/) path instead of /v1/css or /v1/js. I want the url to NOT show the subdirectory, but to show as https://test.com. Then internally have the .htaccess point the /css, /js, /images, etc to /v1/css/, /v1/js/ etc...

apache server:

/
- v1
-.htaccess
  ---css
  ---js
  ---images
  ---index.html
  ---.htaccess

The .htaccess file in the root:

Options +SymLinksIfOwnerMatch 
RewriteEngine On 
RewriteRule ^$ /v1/ [L]

The .htaccess in v1 directory:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
1
  • 1
    Does Base tag work for your? Try adding this to the header of your webpage <base href="/v1/"> This will automatically correct your relative links location forexample: <img src="foo.jpg"> will change its image path to <img src="/v1/foo.png"> Commented Dec 2, 2020 at 4:54

1 Answer 1

0

I was able to get this working using the root directory .htaccess file only thanks to another SO post

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.*) /v1/$1 [L]

<IfModule mod_rewrite.c>
  RewriteBase /v1
  RewriteRule ^v1/index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /v1/index.html [L]
</IfModule>
Sign up to request clarification or add additional context in comments.

Comments

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.