目录
-
前端vue里设置
......
const router = new VueRouter({
base: '/static/userMobile/dist',
mode: 'history',
routes
})
......
我的前端代码放在 /static/userMobile/dist 文件夹下 ,设置base:/static/userMobile/dist,mode:history
原来的地址:http://xxx//static/userMobile/dist/#/user,切换模式后的地址:http://xxx//static/userMobile/dist/user
-
后端设置
用apache
修改根目录下的.htaccess apache重写文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# 前端转发规则
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/static/userMobile/.*$ /static/userMobile/dist/index.html [L]
#多个复制
#后端转发规则
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>
这样设置就可以了
注意
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
这两个条件只对下边第一条规则有用
用nginx
修改nginx 配制文件
......
location / {
......
if (!-e $request_filename) {
# 前端转发规则
rewrite ^/static/userMobile/.*$ /static/userMobile/dist/index.html last;
# 后端转发规则
rewrite ^(.*)$ /index.php?s=/$1 last;
}
......
}
......
用iis
修改根目录下web.config
<rewrite>
<rules>
<clear />
<rule name="2" patternSyntax="Wildcard" stopProcessing="true">
<match url="static/userMobile/dist/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/static/userMobile/dist/index.html" />
</rule>
......
</rules>
</rewrite>
以上就是vue rooter history模式 服务器后端配制
欢迎大神提意见