Forum Moderators: coopster

Message Too Old, No Replies

Help with script that opens htaccess file and writes to it

         

Joe Belmaati

10:22 am on Oct 6, 2004 (gmt 0)

10+ Year Member



I have employed many of the trap/htaccess techniques to my site, and I am really enjoying them. I get hit several times a day by someone looking for formmail scripts. The trapping and mod_rewrite combination is proving an invaluable tool. Thank you to Webmasterworld for providing me with these tools!

As I am slightly concerned that

a. My htaccess file will get bloated
b. Someone with bad intent is doing stuff from their own machine via an AOL or similar proxy

I am trying to create a script that will open my htaccess file once a week and either

a. Write my htaccess instructions to it, thereby clearing out the banned ip's

or

b. Help clear out the SetEnvInf lines with banned ip's.

Is such a script around or does anyone have an idea how to get this done? Once I've got the script runnning I can just ask my host for a cronjob on it.

Any help is MUCH appreciated!
Thank you

Joe Belmaati
Copenhagen Denmark

jatar_k

6:41 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



one option might be to store a default htaccess that you would like to use as the 'cleaned out' version as htaccess.txt

I would store this outside of the root as well to keep it from being accessible via the web.

Then you could set up a crontab to run a little clean up script once a week.

the logic would be something like

1. open default_htaccess.txt for reading
2. get contents of file
3. close default_htaccess.txt
4. open .htaccess for writing, which will truncate the file to zero length
5. write the default htaccess to it
6. close .htaccess
7. maybe send email to you to tell you all was successful or give you any errors that occurred

Joe Belmaati

9:08 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Thank you very much Jatar. I will see if I can get this to work.

Sincerely,
Joe Belmaati
Copenhagen Denmark

jdMorgan

10:21 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To minimize the time that .htaccess will not be available to the server (during which you might get lots of nasty errors, such as suddenly-unprotected directories), I'd suggest:

1. copy .htaccess to .htaccess_temp (details above)
2. rename .htaccess_temp to .htaccess, thereby replacing the old .htaccess file
3. maybe send email to you to tell you all was successful or give you any errors that occurred

To avoid problems, think, "What could go wrong?"... It will. Plan on it.

Jim