SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,077
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    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
      Code:
      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

      Code:
      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.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Cool! I really like the second solution...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •