mod_security2 - ReWrite URL, bypassing Location ReWrites?
mod_security2 - ReWrite URL, bypassing Location ReWrites?
am 25.01.2008 12:27:45 von George Cooke
I want to rewrite a request from a matched REMOTE_ADDR (IP Address),
but I can only find in the mod security reference how to give a
status, which would return my custom error page, but I would like the
client to recieve a 200 status and be re-written to an internal URL,
is this possible?
Also, if you fancy helping even more, I am doing security level
rewrites, but the web app itself has rewrite rules in .htaccess, so
when I try
(mod_rewrite)
RewriteCond %{REMOTE_ADDR}
RewriteRule !^rewrite_dest\.htm$ [L]
It also goes through the .htaccess rewrites... I thought [L] meant
stop processing rules, unless the .htaccess counts as another
rewriteengine instance, I think i've answered my own question? Can
anyone help me get around this? I just want to say, if this IP match,
rewrite to this internal site URL, finish, nothing else, stop, do the
rewrite, no more rewrites, no more incarnations of mod_rewrite, no
nothing, just serve that url please.
If either mod_security or mod_rewrite can do this please let me know.
Thank you very much apache pro's!
Re: mod_security2 - ReWrite URL, bypassing Location ReWrites?
am 25.01.2008 12:32:16 von George Cooke
On 25 Jan, 11:27, boole wrote:
> I want to rewrite a request from a matched REMOTE_ADDR (IP Address),
> but I can only find in the mod security reference how to give a
> status, which would return my custom error page, but I would like the
> client to recieve a 200 status and be re-written to an internal URL,
> is this possible?
>
> Also, if you fancy helping even more, I am doing security level
> rewrites, but the web app itself has rewrite rules in .htaccess, so
> when I try
>
> (mod_rewrite)
> RewriteCond %{REMOTE_ADDR}
> RewriteRule !^rewrite_dest\.htm$ [L]
>
Oh, and I tried [L,S=10] to skip the following rewrites, but they are
still processed.
Re: mod_security2 - ReWrite URL, bypassing Location ReWrites?
am 25.01.2008 14:15:35 von HansH
"boole" schreef in bericht
news:86e5abf9-6b42-4b2b-9690-ac9d5c4c5ac0@l32g2000hse.google groups.com...
>I want to rewrite a request from a matched REMOTE_ADDR (IP Address),
> but I can only find in the mod security reference how to give a
> status, which would return my custom error page, but I would like the
> client to recieve a 200 status and be re-written to an internal URL,
> is this possible?
>
> Also, if you fancy helping even more, I am doing security level
> rewrites, but the web app itself has rewrite rules in .htaccess, so
> when I try
>
> (mod_rewrite)
> RewriteCond %{REMOTE_ADDR}
> RewriteRule !^rewrite_dest\.htm$ [L]
No substitution specifeid in rule
If this is not in a .htaccess a / is missing in the url to match.
If this is in server config while you use vhost, move it to the vhost.
You may have to start the rewriteengine per container
Unsure why you use an not-match ...
Try
RewriteEngine ON
RewriteCond %{REMOTE_ADDR} 1.2.3.4
RewriteRule . /rewrite_dest\.htm [L]
HansH
Re: mod_security2 - ReWrite URL, bypassing Location ReWrites?
am 25.01.2008 15:24:57 von George Cooke
On 25 Jan, 13:15, "HansH" wrote:
> "boole" schreef in berichtnews:86e5abf9-6b42-4b2b-9690-ac9d5c4c5ac0@l32g2000hse .googlegroups.com...>I want to rewrite a request from a matched REMOTE_ADDR (IP Address),
> > but I can only find in the mod security reference how to give a
> > status, which would return my custom error page, but I would like the
> > client to recieve a 200 status and be re-written to an internal URL,
> > is this possible?
>
> > Also, if you fancy helping even more, I am doing security level
> > rewrites, but the web app itself has rewrite rules in .htaccess, so
> > when I try
>
> > (mod_rewrite)
> > RewriteCond %{REMOTE_ADDR}
> > RewriteRule !^rewrite_dest\.htm$ [L]
>
> No substitution specifeid in rule
> If this is not in a .htaccess a / is missing in the url to match.
> If this is in server config while you use vhost, move it to the vhost.
Sorry Hans I wrote this quickly this morning, I should make sure I use
correction citations in future, in the ACTUAL VirtualHost config file,
I do include a substitution, and a leading '/'.
> You may have to start the rewriteengine per container
> Unsure why you use an not-match ...
I am trying to do this:
If the request IP_ADDR matches a given criterea, make sure that client
only ever recevies a certain page whatever they request.
From small experience with rewrites, I have learnt that if you want
only one page to be given whatever the request is, you need to use a
negative match to exlude the rewritted url from being infinatley
rewritten and causing a 500 response code.
I think I would also need to do the same for every image, css etc
which is used in the page, hence meaning a subdirectory would be good
to match against, that isnt a problem, the problem is the fact that I
cant find a way to explicitly rewrite to a URl without processing
further contained rewrites.
>
> Try
> RewriteEngine ON
> RewriteCond %{REMOTE_ADDR} 1.2.3.4
> RewriteRule . /rewrite_dest\.htm [L]
>
> HansH
This would only work for one character matches... which is not the
case in this request(s), it needs to match anything BUT the page I am
rewriting the client to.
Any help would be appreciated.
Re: mod_security2 - ReWrite URL, bypassing Location ReWrites?
am 25.01.2008 15:44:41 von phantom
"boole" wrote in message
news:103cd681-a695-4b22-bc85-33b92f57ba97@v17g2000hsa.google groups.com...
>
> I am trying to do this:
> If the request IP_ADDR matches a given criterea, make sure that client
> only ever recevies a certain page whatever they request.
> From small experience with rewrites, I have learnt that if you want
> only one page to be given whatever the request is, you need to use a
> negative match to exlude the rewritted url from being infinatley
> rewritten and causing a 500 response code.
>
> I think I would also need to do the same for every image, css etc
> which is used in the page, hence meaning a subdirectory would be good
> to match against, that isnt a problem, the problem is the fact that I
> cant find a way to explicitly rewrite to a URl without processing
> further contained rewrites.
>
>>
>> Try
>> RewriteEngine ON
>> RewriteCond %{REMOTE_ADDR} 1.2.3.4
>> RewriteRule . /rewrite_dest\.htm [L]
>>
>> HansH
>
> This would only work for one character matches... which is not the
> case in this request(s), it needs to match anything BUT the page I am
> rewriting the client to.
No, it would work for at least one character matches - the regex only has to
match part of the URI unless you explicitly use the start and end of string
characters - ^$
The [L] *should* prevent the rewritten request from being matched again.
Re: mod_security2 - ReWrite URL, bypassing Location ReWrites?
am 25.01.2008 18:09:20 von HansH
"boole" schreef in bericht
news:103cd681-a695-4b22-bc85-33b92f57ba97@v17g2000hsa.google groups.com...
> On 25 Jan, 13:15, "HansH" wrote:
>> "boole" schreef in
>> berichtnews:86e5abf9-6b42-4b2b-9690-ac9d5c4c5ac0@l32g2000hse .googlegroups.com...>I
>> want to rewrite a request from a matched REMOTE_ADDR (IP Address),
> I am trying to do this:
> If the request IP_ADDR matches a given criterea, make sure that client
> only ever recevies a certain page whatever they request.
> From small experience with rewrites, I have learnt that if you want
> only one page to be given whatever the request is, you need to use a
> negative match to exlude the rewritted url from being infinatley
> rewritten and causing a 500 response code.
That applies mostly to external rewrites aka redirects: the browser will
then make a new request
It may apply to internal _subrequests_ introduced by other sever components
eg mod_include too, adding the NS-flag seems an easy cure:
RewriteRule . /rewrite_dest\.htm [L,NS]
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
> I think I would also need to do the same for every image, css etc
> which is used in the page, hence meaning a subdirectory would be good
> to match against, that isnt a problem, the problem is the fact that I
> cant find a way to explicitly rewrite to a URl without processing
> further contained rewrites.
>>
>> Try
>> RewriteEngine ON
>> RewriteCond %{REMOTE_ADDR} 1.2.3.4
>> RewriteRule . /rewrite_dest\.htm [L]
>
> This would only work for one character matches...
A single-character-only match requires a pattern of ^.$
Without begin and end markers it just matches any character anywhere.
How about
RewriteEngine ON
RewriteMap address txt:/path/to/file/lockedips
RewriteCond %{REQUEST_URI} !^/lockeddown
RewriteRule (.*) ${adress:%{REMOTE_ADDR}|$1} [L]
and listing offencive IPs in /path/to/file/lockedips like
1.2.3.4 /lockeddown/
HansH