静态化 - 伪静态技术(Apache Rewrite 实现)

打开apache的配置文件httpd.conf
找到
#LoadModule rewrite_module modules/mod_rewrite.so
把前面#去掉。没有则添加,但必选独占一行,使apache支持 mod_rewrite 模块
 找到 <Directory "D:/ApacheServer/web"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. #  Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit #  AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> 把 AllowOverride None 换成 AllowOverride All 使apache支持 .htaccess 文件 重启apache服务器 在要启用伪静态的 PHP 项目根目录下建立 .htaccess 文件 在 .htaccess 文件中输入内容 <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^[a-z]+-[a-z]+([0-9]+)-[a-z]+([0-9]+)\.html$ News.php?class=$1&id=$2 </IfModule> 注释: RewriteEngine 为重写引擎开关,on为开启,off为关闭。 RewriteRule 是路由转向规则,^ 符号之后, $ 符号之前,为参数内容,空号包起来的部分,可以在后面用$1,$2.....$n 去获取 ,具体视前面的括号决定。 


例子所在项目为test 在项目下 News.php 页面内写入内容 <?php
echo '<pre>';
print_r($_GET);
echo '</pre>'; 在浏览器中输入 http://localhost/news-class223-id504.html 之后会转向 News.php文件,并输出参数:




转自:http://www.cnblogs.com/dreamhome/archive/2013/07/21/3204165.html

转载于:https://www.cnblogs.com/KTblog/p/5167799.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值