Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Help, 'greater than'

variable greater than

         

ca3le

12:37 pm on Feb 14, 2011 (gmt 0)

10+ Year Member



I'm trying to write a conditional rule that will forward to one place if the variable is less than a curtain number and to a different place if it's greater.

the URLs are like this...

http://siteaddy.blah/t-89234


Basically, I setup a second domain for the old content of my forums and I want everything below a curtain post number to go to there.

I'm knowledgeable with mod_rewrite but I've never written a rule for a greater than condition. Can someone please post an example that I can work from... once I see a working example I can get it from there.

Thank you!
- D

wilderness

3:07 pm on Feb 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



mod_Rewrite does NOT interpret 89234 as the number 89,234, rather as characters, thus you must perceive them the same way.

The following are incomplete statements, however they'll provide the method your looking for.

#uri string does NOT begin with t- then, either an 8 or 9 and the characters must be 0 thru 9 and in a group of 5
RewriteCond %{REQUEST_URI} !^t-[89]
RewriteRule t-([0-9]{5})

jdMorgan

10:16 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The RewriteCond directive supports "lexically-greater-than" and "lexically-less-than" character-string-compare functions.
However, these operate on the entire string, so it will be necessary to first isolate and extract the "number" part so that a lexical compare will behave identically to a numerical compare:

# If "t" is lexically greater than "12345" then go to some-filepath-or-URL
RewriteCond $1 >12345
RewriteRule ^t-([0-9]+) some-filepath-or-URL [flags]
# Else go to some-other-filepath-or-URL
RewriteRule ^t-[0-9]+ some-other-filepath-or-URL [flags]

I used rather generic terms here because it's not clear if you want to externally redirect or internally rewrite in each of the two cases or to externally redirect in both cases.

Jim