yii2.0域名目录绑定(二级域名)以及url美化 url伪静态 Apache ,Ngnix和 IIS

  1. 域名绑定目录前要进行域名解析,域名解析一般在购买商的管理平台上解析,需要一定时间才能正常解析。
  2. vi /etc/httpd/conf/httpd.conf,中搜索VirtualHost example:
    按照注释的示例:
<VirtualHost 98.126.**.226>
    DocumentRoot /var/www/html/*****/frontend/web
    ServerName www.*****.com
    ErrorLog /var/www/html/****_error_log
    CustomLog /var/www/html/****_access_log common
</VirtualHost>

3.重启httpd
service httpd restart,之后即可。但是还没进行url美化,可能会访问到一些404

4.在forntend/config/main.php
urlManager

'urlManager'=> [
            'showScriptName' => false,//隐藏index.php 
            'enablePrettyUrl' => true, 
            'rules' => [
                'index.html'=>'index/main-bg',
                'login.html'=>'***/login',
                'register.html'=>'****/register',
                'introduction/<infos_id:\d+>/<mid:\d+>' =>'modules/introduction', 
            ],
        ],
  1. 服务器开启rewrite,aphace在这里介绍,Ngnix 开启 pathinfo 重写即可,具体方法请自行百度
    在[Apache安装目录]/conf/httpd.conf中找到
    #LoadModule rewrite_module modules/mod_rewrite.so
    去掉#注释
    AllowOverride None”改成“AllowOverride All

  2. 隐藏index.php,在域名index.php同级目录保存.htaccess
    打开编辑器,新建一个空白文档

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

保存为所有格式,名为.htaccess

如果需要是yii2高级模板,则backend要设置二级域名,同样在域名管理中去解析到服务器,把apache设置一下,
1,ServerName 127.0.0.1 修改成ServerName 72.167.11.30

2,#NameVirtualHost * 修改成”NameVirtualHost 72.167.11.30”

3.

<VirtualHost 98.**.**.226>
    DocumentRoot /var/www/html/
    ServerName 98.**.**.226
</VirtualHost>

<VirtualHost 98.**.**.226>
    DocumentRoot /var/www/html/*****/frontend/web
    ServerName www.*****.com
</VirtualHost>

<VirtualHost 98.***.***.226>
    DocumentRoot /var/www/html/****/backend/web
    ServerName admin.*****.com
</VirtualHost>

记得在backend web 下新建.htaccess,按照上面同样做url美化。

———————–华丽的分界线 —————————–
这里更新下 windows服务器IIS下怎么做到域名绑定某个目录,只是简单说下,在IIS管理中添加网站,编辑基本信息,记得把目录选到默认的目录中去,Yii就到web目录去。 然后绑定域名,记得ip那里不要填写,就未分配好了,域名填你的域名,然后 就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值