Jump to content
#FlattenTheCurve ×

John_A

Members
  • Content Count

    64
  • Joined

  • Last visited

Posts posted by John_A


  1. 7 hours ago, benanamen said:

    What are you doing in dev that is not going to be pushed to production? If you are serious about development you shouldn't be in a position where the web host is making changes to your server. A VPS is super super cheap these days and is the equivalent of a dedicated server as far as access and what runs on it. YOU have full control of the server. Of course that means you will need to have or get some server admin skills. There is also no reason you couldn't exactly mirror whatever production setup you have in dev between Vagrant, Containers such as Docker or Virtual Machines.

    You should also be using version control like Git if you are not already. That will allow you to have dev branches and not affect the master codebase until you are ready to merge the changes.

    Nothing, everything is the same there are just slight differences in the way things are done sometimes, e.g. parsing xml as php the syntax is slightly different in .htaccess due to PHP setups differing slightly. 99.9% of the time everything is identical, but there are sometimes a few lines in a .htaccess file somewhere that just have to differ.

    I'm perfectly happy with the hosting I have, I pay for a managed service and it was actually myself who asked for Litespeed on the one in question, initially when it was touted as a faster, drop-in replacement for Apache but it's now evident that there are a few (rare cases) where things have to be done a little differently. I'm happy with the speed improvements that has brought, but at the same time don't want to mess with my dev server at this time as I have other sites live elsewhere that are not on Litespeed but use the same dev server.

    Anyway, it is what it is and I am where I am. I'm quite happy with my setup (dev and multiple live servers), I don't do anything over-complicated. It worked perfectly before this issue (for 10+ years) and hopefully using requinix's solution it will continue to do so - it's no great hardship going forward if I occasionally need to make a .htaccess.dev file if there's a difference between dev and production. All I asked for was a way to quickly clone the existing .htaccess files as per the OP ;)


  2. 1 hour ago, benanamen said:

    You probably should go into it. Experience says whatever you are doing, you are doing it the wrong way. You are asking how to solve your attempted solution which I would pretty much guarantee is not the right approach. If you tell us what the real problem is we can properly advise you.

    OK, here's the background...

    I used to use an environment variable to enable me to differentiate between my dev and production server, using this in .htaccess: -

    <IfDefine DEV_SERVER>
      # dev server specific stuff here
    </IfDefine> 
    
    <IfDefine !DEV_SERVER>
      # production server specific stuff here
    </IfDefine>

    The environment variable "DEV_SERVER" was only ever set on my dev server, and never on production, obviously.

    This approach worked a treat until my production server host installed Litespeed as a replacement for Apache. Litespeed doesn't like the above, and ignores everything.

    I tried having different versions of .htaccess files for dev and production, but that's messy and dangerous, I like to be able to interchange all files at any time between the two.

    My dev server runs Apache 2.4 and I have no plans to change this. I read that you can specify a different filename for .htaccess by putting this in httpd.conf: -

    AccessFileName .htaccess.dev

    But (I think) you can't set an order of preference here (like, say, DirectoryIndex), so I'm thinking the simplest solution so that I can have identical copies is have my dev server use .htaccess.dev instead of .htaccess - the production server will simply ignore any .htaccess.dev files.

    If there's no difference (there doesn't always need to be, it depends on the site and htaccess requirements) then the .htaccess (if there is one) can just be copied and renamed. The dev server will use .htaccess.dev and the live server will still use .htaccess.

    Problem is, I've manually done some already and so that's why if there is already a .htaccess.dev file then it should be left as is.

     

    ETA: I realise this is now no longer a PHP problem, even though my first thought was to do it with a PHP script, it seems that was probably the more complicated approach.


  3. 5 minutes ago, requinix said:
    
    find . -name .htaccess | while read L; do [ -e "$L.dev" ] || cp "$L" "$L.dev"; done

    Find all .htaccess files, and for each one test if there exists a .htaccess.dev and if not copy from the .htaccess.

    Wow, if that works then that's excellent, thanks a lot!

    I'll backup all just in case!


  4. I've got a dev server which, for reasons I won't go into, needs to have different .htaccess files for each site (and subfolders within them) within it. But not always.

    What I need to do is: -

    For the folder I put the PHP script in, and every folder under it (the whole tree under it): -

    • If there's a .htaccess file an no .htaccess.dev file, copy .htaccess and name the copy .htaccess.dev (and look in subfolders)
    • If there's a .htaccess file and also a .htaccess.dev file, do nothing (but keep looking for subfolders)
    • If there's neither a .htaccess or .htaccess.dev file, do nothing (but keep looking for subfolders)

    I'd try to come up with something myself, but getting it wrong will be fairly catastrophic! I'm sure the conditional copy / rename bit is relatively straightforward, but it's the recursive searching of the whole file-system under the script's location that I'm not sure about...

    Any help greatly appreciated, as always!

    I have SSH access, if it's easier done that way maybe I'm approaching it wrong?

     


  5. I have a file in the same location as my PHP file, say test.txt, and in multiple locations it has content like: -

    href="http://www.domain.com/entry.php/256/1/this-is-the-title"
    
    or

    href="http://www.domain.com/entry.php/123/2/another-title"
    
     

    which I need replaced within the file to: -

    href="{EntryNumber=256.link}"
    
    and

    href="{EntryNumber=123.link}"
    
    Only the first number is needed for the replacement, it will be between 1 and 999. Everything between the 5th / and the 2nd " can be safely ignored and removed. This is not the only content in the line, and sometimes there may be more than one occurrence per line.

     

    I've got this so far: -

    $buffer = "";
    $fp = file($file);
    foreach($fp as $line){
       $buffer .= preg_replace(***struggling with this bit***);
    }
    fclose($fp);
    echo $buffer;
    file_put_contents($file, $buffer);
    
    Am I along the right lines generally? And I have no idea what the preg_replace should be as my regex is a bit trial and error, more error in this case...

     

    As always, any help greatly appreciated!

     

    EDIT: If it matters, the largest file I need to edit is 39Kb, and includes 175 occurrences of the replacements.


  6. I have this snippet which is giving a deprecated warning re the "e" pattern modifier in PHP5.5: -

    $result = preg_replace("/\[^a-zA-Z0-9]/e"," ",$result);
    I'm not even sure what the "e" modifier does, as it's not my code...maybe something to do with removing duplicates?

     

    Anyway, what's the best way to replace this so that it doesn't give the warning in PHP5.5, and will work in PHP7.0.0?

     

    I've got a feeling this might work :-

    $result= preg_replace("/\[^a-zA-Z0-9]/"," ",$result);
    but feel I might have over-simplified it, and it maybe doesn't quite do the same thing?

     

    Any help much appreciated!

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.