明凯博客

关注网站技术,一个特立独行的程序员

Isapi_Rewrite中httpd.conf和.htaccess配置规则的区别详解

我们知道,配置伪静态有两种类型的文件,httpd.conf和.htaccess

今天在使用ISAPI_Rewrite3为各个站点配置伪静态时,

发现在全局httpd.conf中配置的伪静态规则可使用,而把配置规则拷贝到网站根目录的.htaccess文件,

并清空全局httpd.conf后却后现伪静态无法使用了。

后来在官网看到了:

If rules are working in httpd.conf file but not in other sections or .htaccess files, make sure to include RewriteEngine on directive in every section and .htaccess file. Also remember that rewriting base inside .htaccess files by default is different from httpd.conf. ISAPI_Rewrite automatically strips the local directory prefix from the path when in .htaccess or section and applies rules only to the remainder. So if your rules start with a ‘/’ character, this should be removed in .htaccess file in the root folder of web site.

原来httpd.conf和.htaccess的规则还是不太一样

如:

httpd.conf中的配置规则是:

1
RewriteRule /(\w+)/list(\d+).html  /Article/ArticleList.aspx\?ArticleType=$1&Page=$2

.htaccess中的配置规则需要修改为:

1
RewriteRule (\w+)/list(\d+).html  /Article/ArticleList.aspx\?ArticleType=$1&Page=$2

根据规则慢慢改过来就可以了。

相关文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注