Publishing VitePress projects using Apache

Last update: 2021-06-12

If you do not want to follow the suggestions in the VitePress deployment guide, or if you are using shared hosting without another option, use the following .htaccess file to publish your VitePress site with Apache.

Place the .htaccess file below in the docs/public folder so that VitePress copies it to .vitepress/dist automatically. Then copy the contents of docs/.vitepress/dist to your Apache public_html directory. Make sure that mod_rewrite is enabled.

conf
DirectoryIndex index.html

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# You can also add other RewriteRules around here
# Redirect 301 /oldurl /a-new-url.html

RewriteRule ^index\.html$ - [L]
ErrorDocument 404 /404.html

# Do not redirect everything else to index, otherwise no 404 will be triggered
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.html [L]
</IfModule>