Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite

exclude pages ending with a string

         

mhamdi

8:14 pm on Jun 28, 2007 (gmt 0)

10+ Year Member



Hi,

I want to rewrite
/any-path/other-path/any-string-(\d+).html using detail.php
except those that end with page-(\d+).html

this is what I have:

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-l
RewriteCond %{REQUEST_URI}!^(.*)page-(\d+)\.htm[l]?(.*)$
RewriteRule (.*)-(.*)\.htm[l]?$ detail.php [QSA,NC]

However all pages get redirected to detail.php

any thoughts?

jdMorgan

7:21 pm on Jun 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mod_rewrite does not universally support all regex conventions used in scripting languages, so I suggest using only those described in the mod_rewrite documentation.

"File exists" checks are very inefficient, and should be avoided when possible. I have re-arranged the code slightly to avoid unnecessary checks. Other tweaks are for parsing efficiency only.


RewriteCond %{REQUEST_URI}!page-[0-9]+\.html?
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-l
RewriteRule ^[^-]+-[^.]+\.htm[l]?$ detail.php [NC,QSA,L]

Jim

[edited by: jdMorgan at 7:21 pm (utc) on June 29, 2007]