Apache配置域名跳转的详细步骤
目录
- 1. 基本知识
- 2. Demo
- 3. 实战
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\Syst编程客栈em32\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配置域名跳转内容请搜索编程客栈(www.devze.com)以前的文章或继续浏php览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!
精彩评论