1. 基本知识
以下主要围绕在 wampserver 中配置 apache 的域名跳转(也称为 虚拟主机跳转 或 域名映射跳转),主要是通过配置 apache 的 httpd-vhosts.conf 文件和 windows 的 hosts 文件来实现的
apache 的虚拟主机功能允许为不同的域名配置不同的网站根目录、端口、跳转规则等
比如访问 http://mytest.local,跳转到本地的 d:/wamp64/www/mytest 网页
apache 配置文件相关路径
主配置文件:
d:/wamp64/bin/apache/apache2.x.x/conf/httpd.conf
虚拟主机配置文件:
d:/wamp64/bin/apache/apache2.x.x/conf/extra/httpd-vhosts.conf
默认未启用,需要确保主配置文件中有这行:
include conf/extra/httpd-vhosts.conf
windows hosts 文件
用于将某个域名映射到本地 ip
比如:127.0.0.1 mytest.local
路径:c:\windows\system32\drivers\etc\hosts
2. demo
在你的 wamp 根目录,比如:
d:/wamp64/www/mytest/index.html
内容如下:
<!-- index.html --> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="refresh" content="0; url=https://www.baidu.com"> <title>跳转中...</title> </head> <body> <p>页面正在跳转中...</p> </body>
第二步:配置 apache 虚拟主机 编辑文件:
d:/wamp64/bin/apache/apache2.x.x/conf/extra/httpd-vhosts.conf
添加以下内容:
<virtualhost *:80> serveradmin webmaster@mytest.local documentroot "d:/wamp64/www/mytest" servername mytest.local errorlog "logs/mytest.local-error.log" customlog "logs/mytest.local-access.log" common </virtualhost>
重启 wampserver 的 apache 服务
打开浏览器访问:http://mytest.local,会看到跳转到https://www.baidu.com
3. 实战
配置域名之后 跳转这两个html文件,一个是测试库,一个是正式库!
简易代码如下,主要用于生成code 以及state的代码解析!
后续新增html文件,不需要重编译,本身是脚本文件!
到此这篇关于apache配置域名跳转的详细步骤的文章就介绍到这了,更多相关apache配置域名跳转内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论