Forum Moderators: phranque

Message Too Old, No Replies

mod-rewrite conditional confusion

mod-rewrite 2nd var

         

arniedobson

1:13 pm on May 13, 2007 (gmt 0)

10+ Year Member



Hi All,

I've been trying for the past hour to figure this one out however I'm not that clued up when it comes to mod-rewrite! I currently have some working code/mod-rewrite which redirects a var starting with '-' to a new location:

RewriteRule ^-(.*)$ [mydomain.net...] [QSA]

This will redirect [mydomain.net...] to [mydomain.net...]

I want to be able to add an amendment which allows for an extra var in the format [mydomain.net...] to [mydomain.net...]

My current code is:

RewriteRule ^-(.*)/(.*).html$ [mydomain.net...] [QSA]

However since the 2nd var isn't always present, it's bombing out when ommited.

Any ideas which will allow it to work with, or without the 2nd var?

Thanks in advance.

jdMorgan

2:29 pm on May 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By far, the simplest solution is to use two rules:

RewriteRule ^-([^/]+)/([^.]+)\.html$ http://www.mydomain.net/view-report.html?s=$1&repdate=$2 [QSA,L]
RewriteRule ^-([^.]+)\.html$ http://www.mydomain.net/view-report.html?s=$1 [QSA,L]

Note the use of more-efficient, unambiguous, negative-match patterns, possibly 20 times faster than "(.*)/(.*)".

Jim