apache下rewrite功能学习笔记

本文介绍如何通过Apache的mod_rewrite模块实现URL重写,使长链接变得更简洁。具体步骤包括启用rewrite模块、配置虚拟主机、设置重写规则等。

首先学习目的是为了是一个很长的连接变得很短比如www.xx.com/xx.php?id=wsl变成www.xx.com/xx/wsl

这就用到了rewrite功能    方法就是在http.conf中写 rewrite ruler   RewriteEngine On
RewriteRule  ^/eharmony/api/(.*)$  /eharmony/api/index.php?s=$1 [L] 

意思是说  到 www.xx.com/eharmony/api/xx  的请求都转发到  www.xx.com/eharmony/api/index.php?s=xx
具体的配置就是

1.将apache下的http.conf中的#LoadModule rewrite_module modules/mod_rewrite.so前面的#去掉

2.在conf下extra下的httpd-vhosts.conf下添加<VirtualHost *:80>
ServerName www.oular.com
ServerAlias www.oular.com
DocumentRoot "D:/wamp/www/oular"
DirectoryIndex index.php index.htm index.html
RewriteEngine On          
RewriteRule  ^/xz/(.*)$  /xz.php?s=$1 [L]  

</VirtualHost>

红色的就是你要写的规则按照个人的需求去写

3.修改   http.conf下添加

<Directory "d:/wamp/www/oular">
Options Indexes FollowSymLinks

Order Allow,Deny
Allow from all
AllowOverride all
</Directory>

4.修改hosts文件下添加127.0.0.1   wwwoular.com

5.这样你的虚拟机下的www.oula.com/xz/wsl 就可以直接的执行www.oular.com/xz.php?id=wsl了

哈哈是不是很神奇


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值