VueJS spa .htaccess

时间:2017-10-05 19:51:08

标签: apache .htaccess vue.js

我试图找出我的.htaccess文件需要的样子。我在我的api的单独https域上运行SPA VueJS应用程序。

我似乎对下面的规则有所帮助,但它不排除/ static文件夹,所以我的资产(字体,CSS等)都没有正确加载。

我似乎无法在Google或SO上找到与我的设置匹配的合适示例(https SPA与api和app在不同的域上)。

<IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^(.*)$ https://my-vue-domain.com/$1 [R]

    RewriteRule ^(static) - [L]

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/static/
    RewriteRule (.*) index.html [QA,L]

</IfModule>

1 个答案:

答案 0 :(得分:0)

如果是/static/js/app.js是您的Document根目录中的真实文件,您根本不需要将其排除,因为您确实排除了所有文件和文件夹:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

我会删除:

RewriteRule ^(static) - [L]

RewriteCond %{REQUEST_URI} !^/static/