- 域名绑定目录前要进行域名解析,域名解析一般在购买商的管理平台上解析,需要一定时间才能正常解析。
- 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',
],
],
服务器开启rewrite,aphace在这里介绍,Ngnix 开启 pathinfo 重写即可,具体方法请自行百度
在[Apache安装目录]/conf/httpd.conf中找到
#LoadModule rewrite_module modules/mod_rewrite.so
去掉#注释
AllowOverride None”改成“AllowOverride All隐藏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那里不要填写,就未分配好了,域名填你的域名,然后 就可以了。