Maximus
Maximus

Reputation: 2976

mod rewrite not reading the rule from htaccess file

I am using WAMP (apache 2.2.9 and PHP 5.4.17). I have few simple mod rewrite rules that are working on production server (CentOS) but on my windows machine one rule is being ignored. I spent 3 days on finding solution but none worked.

Here is mod rewrite rules

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]

The first rewrite rule is being ignored by Apache. Surprisingly, when I remove all contents from htaccess it still reads my rules. I have turned on mod rewrite log and here is the log detail

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

As you can see above, instead of rewriting above request to page-review.php it reads reviews.php file

Here is another request which works fine

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

Upvotes: 1

Views: 502

Answers (1)

anubhava
anubhava

Reputation: 785196

Rules mostly look alright. Try this slightly modified code:

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 regex in your last rule won't match file/downloads/software/f5983-docs.html

Upvotes: 1

Related Questions