首先确定使用的 Apache 版本,以及是否加载了 mod_rewrite 模块。
版本查看命令C:\>apache -v
Server version: Apache/2.0.58
Server built: Apr 29 2006 17:47:10
若为Apache 1.x
检查 conf/httpd.conf 中是否存在如下两段代码:
#LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c
若为Apache 2.x(就像偶使用的)
检查 conf/httpd.conf 中是否存在如下一段代码:
#LoadModule rewrite_module modules/mod_rewrite.so
把LoadModule前边的#去掉,然后在网站根目录添加.htaccess(内写伪静态正则代码,这个文件可以在conf/httpd.conf 中的AccessFileName .htaccess指定),也可以直接在conf/httpd.conf中添加伪静态正则代码。然后重启apache(apache -k restart)就可以使用伪静态地址啦。
如果没有安装 mod_rewrite,可以重新编译 Apache(或若为win系统建议重新安装),并在原有 configure 的内容中加入 –enable-rewrite=shared,然后再在 Apache 配置文件中加入正则代码。
正则代码类似:
RewriteEngine On
RewriteRule ^(.*)/(index-)?([0-9]+)(\.html)?$ $1/index.php?page=$3
转载原创文章请注明,转载自:[Lin's Space|Only]
本文链接: http://clin003.com/servers/apache-rewrite-config-526/
Google比较注重原创性和时效性,若没有找到需要的内容可尝试以下搜素。
@箱子
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
#上面的不要修改,下面为规则
RewriteCond $1 !^(index\.php|static|install|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
#httpd.ini
#正则表达式中都是用“\”进行转义的,httpd.ini中只需转义(屏蔽掉)问号就OK了。
#如果需要忽略大小写,可以在每一条规则最后加上[I] (ignore的缩写)。
能帮我把 EasySns的伪静态.htaccess转换成 IIS上面的 .http吗?
RewriteEngine on
RewriteCond $1 !^(index\.php|static|install|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Pingback: 允许浏览目录(目录列表)访问,让爬虫更轻松的索引网站文件 – Lin's Space|Only