ubuntu环境个人主页的搭建以及301重定向

域名

讲义选用name.me之类的域名

web服务器

安装mysql

sudo apt-get update
sudo apt-get install mysql-server mysql-client

过程中如果不要求输入密码的话,可以使用vim查看初始密码

vim /etc/mysql/debain.cong

安装apache2

sudo apt-get install apache2

然后查看http://localhost,如果成功安装会有apache2的默认主页

安装php

sudo apt-get install php7.0 libapache2-mod-php
/etc/init.d/apache2 restart

设置301重定向

为什么要设置

保证二级域名均跳转至name.me

使用rewrite模块

sudo a2enmod rewrite
systemctl restart apache2
/etc/init.d/apache2 restart

然后修改站点的默认规则

vim /etc/apache2/sites-available/000-default.conf

文件的默认内容为

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

</VirtualHost>之前加上

RewriteEngine on

RewriteCond %{SERVER_NAME} =www.nameofsite.topname
RewriteRule ^ http://hengli.me%{REQUEST_URI} [END,NE,R=permanent]

RewriteCond %{SERVER_NAME} =nameofsite.topname
RewriteRule ^ http://name.me%{REQUEST_URI} [END,NE,R=permanent]

其他规则类似,先启用rewrite模块,RewriteCond写需要301跳转的网址,RewriteRule写跳转的目标网址。

©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值