Ignore .htaccess in local environment

Hi,

I’ve got some .htaccess files which perform rewrites and redirect errors to logs on my production server. I’d like to keep a copy of the .htaccess files locally, at the same time preventing the actions from firing when in my local environment. Is there a way to either ignore the .htaccess files altogether or check if I’m accessing the .htaccess files locally from within the .htaccess file?

Thanks so much,

Eric

There are two ways you can do this.

  • Assuming the production domain is different than your development domain, check for the current domain in the RewriteRule

    RewriteCond %{HTTP_HOST} ^www\\.myproductiondomain\\.com$ [NC] RewriteRule ^something$ /something-else
  • Assuming you have access to httpd.conf on your localhost change the value of AccessFileName in there. Something like


    AccessFileName .htaccess-dev .htaccess


    The nice thing about this is that Apache will parse the first file that exists and skip all others. So if for some project you only have a .htaccess file it will parse that, but as soon as you add a .htaccess-dev file it will parse that and ignore the .htaccess file.

My personal preference is the second option, since I don’t like environment checks in a production environment.

Cool! I really like the second solution…