mod重写不读取htaccess文件中的规则

时间:2013-08-23 13:57:08

标签: .htaccess apache2

我正在使用WAMP(apache 2.2.9和PHP 5.4.17)。我有几个简单的mod重写规则正在生产服务器(CentOS),但在我的Windows机器上,一个规则被忽略。我花了3天时间找到解决方案但没有工作。

这是mod重写规则

Options -Indexes FollowSymLinks MultiViews

RewriteEngine on
RewriteBase /mysite/

RewriteRule ^reviews/([a-zA-Z0-9_-]+)/([0-9]+)/(.*).html$ page-review.php?t=$1&m=$2&s=$3 [L] #This is being ignored by Apache
RewriteRule ^reviews/?$ reviews.php [L]
RewriteRule ^reviews/([a-zA-Z0-9_-]+)-reviews/?$ reviews.php?r=$1 [L]
RewriteRule ^file/([a-zA-Z0-9_-]+)/s([0-9]+)-([a-zA-Z0-9_-]+)/f([0-9]+)-(.*).html$ file.php?c=$1&s=$2&st=$3&&m=$4&t=$5 [L]

Apache忽略了第一个重写规则。令人惊讶的是,当我从htaccess中删除所有内容时,它仍然会读取我的规则。我打开了mod重写日志,这里是日志细节

log for http://localhost/mysite/reviews/product/11/samsung.html

127.0.0.1 - - [23/Aug/2013:14:37:34 +0100] [localhost/sid#453140][rid#1821000/subreq] (1) [perdir /mydir/] pass through /mydir/reviews.php
127.0.0.1 - - [23/Aug/2013:14:37:34 +0100] [localhost/sid#453140][rid#17cc4f0/initial] (1) [perdir /mydir/] pass through /mydir/reviews.php
127.0.0.1 - - [23/Aug/2013:14:37:34 +0100] [localhost/sid#453140][rid#17d0500/initial] (1) [perdir /mydir/] pass through /mydir/reviews.php
127.0.0.1 - - [23/Aug/2013:14:37:34 +0100] [localhost/sid#453140][rid#1835050/initial] (1) [perdir /mydir/] pass through /mydir/reviews.php

正如您在上面所看到的,不是将上述请求重写为page-review.php,而是将其读取为reviews.php文件

这是另一个工作正常的请求

log for http://localhost/mysite/file/downloads/software/f5983-docs.html

127.0.0.1 - - [23/Aug/2013:14:39:42 +0100] [localhost/sid#453140][rid#47f4188/initial] (2) [perdir /mydir/] rewrite 'file/downloads/software/f5983-docs.html' -> 'file.php?c=downloads&s=45&st=software&&m=5983&t=docs'
127.0.0.1 - - [23/Aug/2013:14:39:42 +0100] [localhost/sid#453140][rid#47f4188/initial] (2) [perdir /mydir/] trying to replace prefix /mydir/ with /mysite/
127.0.0.1 - - [23/Aug/2013:14:39:42 +0100] [localhost/sid#453140][rid#47f4188/initial] (1) [perdir /mydir/] internal redirect with /mysite/file.php [INTERNAL REDIRECT]
127.0.0.1 - - [23/Aug/2013:14:39:42 +0100] [localhost/sid#453140][rid#47ed3e0/initial/redir#1] (1) [perdir /mydir/] pass through /mydir/file.php

1 个答案:

答案 0 :(得分:1)

规则大多看起来不错。试试这个稍微修改过的代码:

Options -Indexes +FollowSymLinks -MultiViews

RewriteEngine on
RewriteBase /mysite/

RewriteRule ^reviews/(\w+)/([0-9]+)/([^.]+)\.html$ page-review.php?t=$1&m=$2&s=$3 [L,QSA,NC]
RewriteRule ^reviews/?$ reviews.php [L,NC]
RewriteRule ^reviews/(\w+)-reviews/?$ reviews.php?r=$1 [L,QSA,NC]
RewriteRule ^file/(\w+)/s([0-9]+)-(\w+)/f([0-9]+)-([^.]+)\.html$ file.php?c=$1&s=$2&st=$3&&m=$4&t=$5 [L,QSA,NC]

您上一条规则中的Btw正则表达式与file/downloads/software/f5983-docs.html

不匹配