tp框架+vuerouter history模式刨过的坑

目录

前端vue里设置

后端设置

用apache

用nginx

用iis


  • 前端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模式 服务器后端配制

欢迎大神提意见

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值