apache配置rewrite(静态化)

Home > 今日一点, 服务器 > apache配置rewrite(静态化)

首先确定使用的 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比较注重原创性和时效性,若没有找到需要的内容可尝试以下搜素。

This entry was posted in 今日一点, 服务器 and tagged , , . Bookmark the permalink.

3 Responses to apache配置rewrite(静态化)

  1. 白菜林 says:

    @箱子

    [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的缩写)。

  2. 箱子 says:

    能帮我把 EasySns的伪静态.htaccess转换成 IIS上面的 .http吗?

    RewriteEngine on
    RewriteCond $1 !^(index\.php|static|install|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]

  3. Pingback: 允许浏览目录(目录列表)访问,让爬虫更轻松的索引网站文件 – Lin's Space|Only

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>