Home  >  Article  >  php教程  >  使用apache模块rewrite_module (转)

使用apache模块rewrite_module (转)

WBOY
WBOYOriginal
2016-06-13 12:33:24823browse


[url]http://wwww.aaaaaaaaa.com/...
的地址形式改为
[url]http://wwww.aaaaaaaaa.com/...
或者
[url]http://wwww.aaaaaaaaa.com/...
当然可以按照你的要求随便变.
APACHE的 MOD_rewrite模块.
大家可以看一个演示的一个 PHP学习论坛
[url]http://www.phpx.com/happy/...
这个论坛的版面和帖子,就是运用了这个技术,地址静态化.但是是假的.
这个技术哪里好?
可以让baidu, google等收入你的站点所有页面.
收入地址就是你的假静态地址.当然别人看不出你是假的.而且这个技术隐藏了你背后执行的程序.
你可以把
/soft/1234.html 重写传递给 soft.php?id=1234
当然你改一下名 换成 softxfewafew.php?id=1234
表面还是 soft/1234.html但是你 APACHE内部执行了你重写的文件.
从根本上可以防止别人从程序本身入侵.

下面我写怎么样重写.分为 WINDOWS和LIUNX2种
都是操作
APACHE安装文件夹内的 CONF文件夹里面的httpd.conf
打开以后,找到
#LoadModule rewrite_module "modules/mod_rewrite.so" 
把#去掉.
然后找到虚拟主机配置
在虚拟主机中加入
RewriteEngine On 
RewriteRule ^/soft/([0-9]+).html$ /soft.php?id=$1 
//解释
//WWW.玉米.COM/SOFT/1234.HTML
//重写为
//WWW.玉米.COM/soft.php?id=1234
//这里ID是可以变的 你给它 1 就是传递1
RewriteRule ^/([0-9]+).html$ /soft.php?id=$1 
//解释
//WWW.玉米.COM/1234.HTML
//重写为
//WWW.玉米.COM/soft.php?id=1234
RewriteRule ^/([0-9]+)_([0-9]+).html$ /soft.php?id=$1&catid=$2
//解释
//WWW.玉米.COM/1234_2222.HTML
//重写为
//WWW.玉米.COM/soft.php?id=1234&catid=2222
当然随便你怎么换!
这就是 WIN下的.
LIUNX下是一样的 但是要加
开始
结束
重写都加在虚拟主机设置中.
如果没有虚拟主机,那加在最后!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn