Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Cron Job to replace .htaccess

Discussion in 'General Discussion' started by metrocard, Oct 20, 2010.

  1. metrocard

    metrocard Registered

    Oct 20, 2010
    Likes Received:
    Trophy Points:
    So, I have a huge .htaccess file to block all non-US IPs. (This is the only way I can do this since I'm on shared hosting and can't do IP tables)

    The downside to using .htaccess is that a huge one slows down the site. I would like to make a cron job that replaces the .htaccess file with with a different one during the night and then replace that one with the original in the morning. This way, the site is only slowed down during the night when there aren't many people on. (My site is targeted towards a small group of people and having it open to the entire world just opens the site up to spam)

    For example
    /Folder1/.htacess <-- with IP block
    /Folder2/.htacess <-- without IP block
    /.htacess <-- current .htaccess without IP block.

    At 12:00 AM, it copies the .htaccess from Folder1 and replaces the one in the root directory. Then at 8:00 AM, it copies the .htaccess from Folder2 to replace the one in the root.

    Is this possible? If it is, can someone help me achieve this?

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice