首先,要开启rewrite功能:
LoadModule rewrite_module modules/mod_rewrite.so
重启apache,使配置生效。
下面介绍rewrite的使用:
<VirtualHost *:80>
RewriteEngine on
修改如下代码:
RewriteRule ^(.*)/list-([0-9]+)-([0-9]+)\.html$ $1/list.php?forum_id=$2&page=$3
这一行,把
http://it.net.cn/list.php?forum_id=5&page=1 转换成 http://it.net.cn/list-5-1.html
访问地址为http://it.net.cn/list-5-1.html,实际地址是 http://it.net.cn/list.php?forum_id=5&page=1
方法2:
复制代码代码示例:
<IfModule mod_rewrite.c>
RewriteEngine on RewriteRule ^(.*)/list-([0-9]+)-([0-9]+)\.html$ $1/list.php?forum_id=$2&page=$3 RewriteRule ^(.*)/detail-([0-9]+)-([0-9]+)\.html$ $1/detail.php?thread_id=$2&page=$3 < /IfModule>
例子1:
复制代码代码示例:
< IfModule mod_rewrite.c>
RewriteEngine on RewriteRule ^([0-9]*).htm$ show.php?ID=$1 < /IfModule> 或 RewriteEngine On RewriteBase / RewriteRule ^([0-9]*).htm$ show.php?ID=$1 或 RewriteEngine On RewriteRule ^([0-9]*).htm$ show.php?ID=$1
注意: |