Forum Moderators: phranque
I'm trying to only conduct mod_rewrites on folders that contain a specific string "-community". So /office-community/ should use the redirects where as /timothy/ should not.
Here is my condition:
RewriteCond %{THE_REQUEST} ^[A-Z]+[-community]
But if I goto /timothy/ it is still attempting to redirect me. Please advise and many thanks!
RewriteRule ^([^/]+[-community])/?$ /community_luke/browse.php?category=$1 [L]
RewriteRule ^([^/]+[-community]+)/login/?$ /community_luke/login.php [L]
RewriteRule ^([^/]+[-community]+)/register/?$ /community_luke/signup.php [L]
You should be able to get the required function simply by correcting your RewriteRule patterns. Something like:
RewriteRule ^([^-]+-community)/?$ /community_luke/browse.php?category=$1 [L]
RewriteRule ^([^-]+-community)/login/?$ /community_luke/login.php [L]
RewriteRule ^([^-]+-community)/register/?$ /community_luke/signup.php [L]
You may also exclude specific characters, as we did above with [^-]+ meaning, "Match one or more characters NOT equal to a hyphen," or equivalently, "Match up to the first hyphen."
Also be aware for future reference that a RewriteCond affects only the first RewriteRule that follows it. If you wish a condition to affect more than one rule, you must construct a negative-logic rule that skips over those multiple rules if that condition is NOT true.
For example:
# If URL does NOT contain "-community/", then leave it alone and skip the next 39 rules
RewriteRule !-community/ - [S=39]
#
RewriteRule ^([^-]+-community)/?$ /community_luke/browse.php?category=$1 [L]
RewriteRule ^([^-]+-community)/login/?$ /community_luke/login.php [L]
... 37 more rules to be skipped
#
# unconditional code execution resumes below this line
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim