Gossamer Forum
Home : General : Internet Technologies :

mod_rewrite "order of operations" for RewriteCond

Quote Reply
mod_rewrite "order of operations" for RewriteCond
I'm trying to set up a series of RewriteCond conditions, and basically 4 out of 5 are "or" while the last is an "and". In other words, the condition should be a match if the 5th item is true AND ANY of the 1st 4 are true. I'm not quite sure how to do this, though. Is the following correct? (I'm trying to make sure that a few directories and scripts are only ever accessed securely).

RewriteCond %{REQUEST_URI} ^first.* [NC,OR]
RewriteCond %{REQUEST_URI} ^second.* [NC,OR]
RewriteCond %{REQUEST_URI} ^third.*$ [NC,OR]
RewriteCond %{REQUEST_URI} ^fourth.*$ [NC]
RewriteCond %{SERVER_PORT} !443$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Many thanks.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] mod_rewrite "order of operations" for RewriteCond In reply to
How about:

RewriteCond %{REQUEST_URI} ^(first|second|third|fourth).*$ [NC]
RewriteCond %{SERVER_PORT} !443$
RewriteRule ^/?(.*)$ https://www.example.com/$1 [R=301,L]

Alternatively, if you had to do or's and and's, I think you can do it with chained rules.

Cheers,

Alex
--
Gossamer Threads Inc.