SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Threaded View

  1. #1
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,904
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)

    Is it possible to have a single .htaccess file for both localhost and online

    Hi All,

    Unfortunately I have Googled and not been able to find a solution so...


    Problem:
    Two different .htaccess files required for http://localhost and http://MySite.com
    Having to maintain two different .htaccess files with the same name.
    Try to prevent renaming and uploading incorrect .htaccess files

    Requirements:
    I would prefer a single .htaccess file that detects HOST and performs relevant script

    Reason:
    I struggle with Apache's htaccess and have a hard job in trying to find the relevant
    information in the wealth of free advice

    Solution:
    With PHP this is a simple task:

    # PHP eqivalent to Apache .htaccess file
    PHP Code:

    #test host
      
    defined('LOCALHOST') ? NULL define('LOCALHOST'in_array($_SERVER['SERVER_NAME'], array('localhost''127.0.0.1') ));

    # condition for specific host
      
    if( LOCALHOST )
      {
        include 
    'htaccess-for-localhost.php'
       
    # Read somewhere that not availalble in Apache
      
    }
      else 
    # if( ! LOCALHOST )
      
    {
        include 
    'htaccess-for-MySite.php'
      }
      
    #Common stuff
      
    ErrorDocument 404 /404.php 
    Last edited by John_Betong; Mar 14, 2012 at 22:17. Reason: formatting comments
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014


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
  •