Apache rewrite规则的配置过程

简介:

Apache rewrite规则的配置过程

服务器端:192.168.10.201 (RHEL 5.9)
客户端:192.168.10.40(Linux)
        192.168.10.246 (windows xp)

1.安装Apache
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# ls /etc/httpd/modules/mod_rewrite.so
mod_rewrite.so  ##检查确定有此模块

vim /etc/httpd/conf/httpd.conf 
LoadModule rewrite_module modules/mod_rewrite.so ##检查确定有此行
2.创建基于域名的虚拟主机
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<VirtualHost *:80>
ServerAdmin   hunk.test.com
DocumentRoot  "/var/www/html/hunk"
ServerName  192.168.10.201
RewriteEngine on               ##打开rewirte功能
Include conf.d/hunk-rewrite.conf
</VirtualHost>

3.写rewrite规则
[root@localhost ~]# vim /etc/httpd/conf.d/hunk-rewrite.conf 
RewriteCond %{HTTP_HOST} hunk.test.com [NC]
RewriteRule  ^(.*)/index.html$  http://hunk.test.com/test.html [L,R=302]

4.在/var/www/html/hunk 添加测试页面。
[root@localhost ~]# vim /var/www/html/hunk/index.html 
<html>
<head>
<title>
test page
</title>
</head>
<body >
<p align="center">
<font size="32px" color="red">
this is test page !page jump failure!
</font>
</p>
</body>
</html>

[root@localhost ~]# vim /var/www/html/hunk/hunk.html 
<html>
<head>
<title>
test page
</title>
</head>
<body >
<p align="center">
<font size="32px" color="red">
this is test page !page jump success!
</font>
</p>
</body>
</html>


客户端设置
5.修改hosts文件
xp:C:\Windows\System32\drivers\etc\hosts
192.168.10.246 hunk.test.com  ##添加此行
  访问hunk.test.com/index.html 
                     this is test page !page jump success!

wKiom1RTU1DSiFOZAAGpXNVVQrg789.jpglinux :
[root@localhost ~]# vim /etc/hosts 
192.168.10.40        hunk.test.com
[root@localhost ~]# elinks --dump hunk.test.com/index.html
                     this is test page !page jump success!

wKiom1RTU9_TbdNOAAMlTbzyLlw807.jpg


注意:

1.书写rewrite需要知道正则表达式的知识。

在RewriteRule  ^(.*)/index.html$  http://hunk.test.com/test.html [L,R=302]中,^表示以某某开头,$表示以某某结尾, .(点)表示匹配任意单个字符,*表示匹配前面的子表达式零次或多次(大于等于0次)

2.这里搭建的是基于域名的虚拟主机的web服务器,所以下面两行代码是在/etc/httpd/conf.d/vhosts.conf书写。说明是此服务器也就是hunk.test.com 打开rewrite功能,并应用规则。

RewriteEngine on               ##打开rewirte功能
Include conf.d/hunk-rewrite.conf

 如果不是基于虚拟主机的web服务器,上面两行需要在/etc/httpd/conf/httpd.conf书写。




      本文转自独弹古调  51CTO博客,原文链接:http://blog.51cto.com/hunkz/1570459,如需转载请自行联系原作者





相关文章
|
1月前
|
SQL Apache HIVE
一文彻底掌握Apache Hudi的主键和分区配置
一文彻底掌握Apache Hudi的主键和分区配置
65 0
|
2月前
|
Java 程序员 API
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
59 1
|
2月前
|
前端开发 Java 数据库连接
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
33 0
|
6月前
|
PHP Apache
PHP环境搭建(配置php模块到apache服务器)
PHP环境搭建(配置php模块到apache服务器)
65 0
|
6月前
|
Linux 网络安全 Apache
百度搜索:蓝易云 ,linux系统 Apache服务配置教程。
现在,您可以通过浏览器访问您的网站。在浏览器中输入服务器的IP地址或域名,即可访问默认网站或配置的虚拟主机。以上是在Linux系统上配置Apache服务的教程。请根据您的需求进行必要的配置和修改。
83 0
|
7月前
|
Apache PHP 数据安全/隐私保护
(MAC)PHP Apache 安装与配置
(MAC)PHP Apache 安装与配置
223 0
|
1月前
|
安全 Linux Apache
Apache代理服务器搭建和配置
Apache代理服务器搭建和配置
|
7月前
|
网络协议 Linux 应用服务中间件
2022红帽企业版网络配置--centos7配置DHCP DNS绑定域名 FTP HTTP(apache) nginx samba
2022红帽企业版网络配置--centos7配置DHCP DNS绑定域名 FTP HTTP(apache) nginx samba
151 0
|
1月前
|
运维 Linux Apache
LAMP架构调优(九)——Apache Rewrite功能实战
LAMP架构调优(九)——Apache Rewrite功能实战
13 1

热门文章

最新文章

推荐镜像

更多