help redirecting all other URLS

Using mod_rewrite to handle various content issues

help redirecting all other URLS

Postby adsmart » Sat Dec 16, 2006 4:26 pm

hey all,

I have a slightly tricky question. I have a subdomain dedicated solely to handling form mail. The only real legit access anyone is going to have to this subdomain is via links from our main domain. I will only ever have a very limited list of valid URLs that can be requested and I want to make sure that anyone who is trying anything hinky (mostly spambots) get punished.

I have only three static pages, a simple index page that any one who makes a mistake will get to (also the root of the subdomain), a static Tech support form and a robots.txt. I also have 2 scripts. Form.pl which simply serves the form to the browser, formmail.pl which handles sending the mail. I'm also waffling between a poison script (to punish spammers) and simply sending a 403 (forbidden) or 410 (gone).

The following bit (in my .htaccess which is where I'm allowed to do this) and it works fine for what it does:

Code: Select all
RewriteRule ^mailbox/([0-9]+)/?$ /form.pl?mailbox=$1 [NC,L]
RewriteRule ^mailbox/([0-9]+)/send/?$ /formmail.pl?recipient=$1 [NC,L]
RewriteRule ^$ /index.html [L]


The problem occurs when I want to send everything that is not one of these (or robots.txt) to my poison script. I've tried a whack of variations and this is my latest failed attempt:

Code: Select all
RewriteCond %{REQUEST_FILENAME} !^$
RewriteCond %{REQUEST_FILENAME} !^robots\.txt$ [NC]
RewriteCond %{REQUEST_FILENAME} !^mailbox/([0-9]+)/?$ [NC]
RewriteCond %{REQUEST_FILENAME} !^mailbox/([0-9]+)/send/?$ [NC]
RewriteRule .* /poison.pl [L]


Regardless of where I put it, I 500 errors which seems to suggest that there is an infinite loop happening somewhere.

Any thoughts?

A


[/code]
adsmart
 
Posts: 3
Joined: Sat Dec 16, 2006 4:07 pm

Postby richardk » Sun Dec 17, 2006 10:29 am

Try
Code: Select all
RewriteCond %{REQUEST_URI} !^/mailbox/[0-9]+(/send)?/?$ [NC]
RewriteRule !^(robots\.txt|index\.html|poison\.pl)?$ /poison.pl [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby adsmart » Sun Dec 17, 2006 4:15 pm

That's almost right but every request to /mailbox/0/ goes to poison.pl still. I'm not sure why that is. It seems like each time you rewrite the URL the processing happens all over again.

Adam
adsmart
 
Posts: 3
Joined: Sat Dec 16, 2006 4:07 pm

Postby richardk » Mon Dec 18, 2006 9:54 am

It seems like each time you rewrite the URL the processing happens all over again.

It does. It's a new (sub) request. So you need to stop it rewriting sub requests:
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/mailbox/[0-9]+(/send)?/?$ [NC]
RewriteRule !^(robots\.txt|index\.html|poison\.pl)?$ /poison.pl [L]


Or stop it rewriting form.pl and formmail.pl:
Code: Select all
RewriteCond %{REQUEST_URI} !^/mailbox/[0-9]+(/send)?/?$ [NC]
RewriteRule !^(robots\.txt|index\.html|(poison|form(mail)?)\.pl)?$ /poison.pl [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby adsmart » Mon Dec 18, 2006 11:59 am

Perfect thanks. I'll keep the rewrite_status in my back pocket for next time.

A
adsmart
 
Posts: 3
Joined: Sat Dec 16, 2006 4:07 pm


Return to Content

Who is online

Users browsing this forum: No registered users and 11 guests

cron