配置二级域名

1.配置虚拟域名,打开apache/conf/extra/httpd-vhosts.conf文件

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "F:\PHP\test\Multi-store-mall-ThinkPHP5.1\think\public"
    ServerName mall.msm.cn  #域名
    ServerAlias malladmin.msm.cn    #域名别名(配合TP5.1配置二级域名)
    ErrorLog "logs/mall.msm.cn-error.log"
    CustomLog "logs/mall.msm.cn-access.log" common
</VirtualHost>

2.配置本地hosts文件

127.0.0.1    mall.msm.cn
127.0.0.1    malladmin.msm.cn

3.apache开启rewrite模块,更改TP5.1/public下的伪静态文件,隐藏入口文件index.php

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>

4.TP5.1开启二级域名,更改route/route.php文件

use think\facade\Route;

//配置tp5.1二级域名
Route::domain('mall', 'index');    mall.msm.cn指向index模块
Route::domain('malladmin', 'admin');    malladmin.msm.cn指向admin模块

猜你喜欢

转载自www.cnblogs.com/daijiandong/p/12067344.html