Welcome to WebmasterWorld Guest from 174.129.96.175

Forum Moderators: Ocean10000 & incrediBILL & phranque

rewrite rule .(tld)

rewriting tld's keeps repeating rule, how would we stop that

   
1:05 pm on Nov 20, 2012 (gmt 0)



This:

RewriteCond %{HTTP_REFERER} ^http(s)?://(.*)?\.(tld|tld)(/.*)?$
RewriteRule ^(.*)$ http://www.example.com/log.cgi [R=301,L]

Works fine but for obvious reasons keeps redirecting. So far I've tested [ ], [R], [R=301,L] and [L]. All result in multiple redirects. Up to (5 times, Total elapsed time: 0 seconds)

Tested, RewriteOptions MaxRedirects=2, no change.

I could [F], but thats no fun
1:11 pm on Nov 20, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Internally rewrite (rather than externally redirect) to a script that serves whatever status code you require and sends out the human readable page content at the originally requested URL. This script can then also internally call the log file script.

>>
RewriteCond %{HTTP_REFERER} ^http(s)?://(.*)?\.(tld|tld)(/.*)?$ 


http(s)? simplifies to https? The brackets are not needed on a single character.

Leading
(.*)?
is a problem. The
*
means "or zero" so the question mark is redundant. The brackets are also redundant as you're not reusing anything.

(/.*)?$
is "slash followed by something or nothing, OR nothing at all, not even a slash". Simplifies to
/?
and nothing else, especially not the $ anchor. Again, brackets are not required as you're not needing to capture anything for re-use.
7:50 pm on Nov 20, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Works fine but for obvious reasons keeps redirecting. So far I've tested [ ], [R], [R=301,L] and [L]. All result in multiple redirects. Up to (5 times, Total elapsed time: 0 seconds)

Empty flag? Really? I've never tried that: would expect a 500-class error.

A redirect goes into an infinite loop because each request is an island, and redirecting doesn't change the referer. (Neither does reloading the page.) So the [L] flag will only affect the rest of mod_rewrite. Since you've given the complete protocol and domain, it is de facto an [R] of some kind, regardless of other flags.

Rewrite and redirect are different things-- as is [F] of course-- so you have to decide what you want your result to be and make a rule for that.

Once you've figured out whether you want a redirect or a rewrite you can figure out how to exclude requests that have already been handled.

Does (tld|tld) in the initial Rule mean that you want to exclude two different tld's like-- picking an example wholly at random-- .ru and .su? You can use any tld in posts, so long as the meat of the name is example dot something.
8:27 pm on Nov 20, 2012 (gmt 0)



Empty flag? Really?

No, didn't know how to write "nothing".

... each request is an island

right

... exclude two different tld's

Yeah, or three

I want log.cgi to write to log. I can, like G1smd says, send it to page and put exec. script, or an SSI, on the page.

All that [r] stuff was just me testing for an end to redirect. I know it's all superfluous.

Whether I "can figure out how to exclude requests" is doubtful, at best lengthy. I don't do this everyday and forget what I get pretty fast.

All I want is to not allow (.spyonus or .datamineme) on the site and record info (who,what,where...). Which I do now.

I was trying a different approach with the text.cgi as opposed to the [F] and - recurring redirect came up.

I guess I have to 403 them first, whatever I might do next. Yes?
9:57 pm on Nov 20, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month





Swap the external redirect for an internal rewrite in the RewriteRule.

Once you fix the other syntax errors, you simply need another RewriteCond that excludes requests that have already been rewritten.

The simplest will be
RewriteCond %{REQUEST_URI} ^/log\.cgi
or similar.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month