homepage Welcome to WebmasterWorld Guest from 54.167.144.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
rewrite rule .(tld)
rewriting tld's keeps repeating rule, how would we stop that
dougwilson



 
Msg#: 4520719 posted 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

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4520719 posted 1:11 pm on Nov 20, 2012 (gmt 0)

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.
lucy24

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



 
Msg#: 4520719 posted 7:50 pm on Nov 20, 2012 (gmt 0)

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.

dougwilson



 
Msg#: 4520719 posted 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?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4520719 posted 9:57 pm on Nov 20, 2012 (gmt 0)



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.
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved