Snippets

RuWeb.net htaccess_php_off

Created by Andrey Chesnakov last modified
#!/usr/bin/perl -w
use strict;

my $fname=$ARGV[0];

if (!$fname) {
    print "\nUsage: find /home/ -name .htaccess -exec /root/htaccess_php_off.pl {} \\; | tee htaccess_php_off.log \n";
    # also not forget to fix file owners
    # cd /home; for user in */; do find $user -user www -not -name tmp -exec chown -hvv ${user%/} {} +; done
    exit;
}

open(FILE, "<$fname") || die "File not found";
my @lines = <FILE>;
close(FILE);

my @newlines;
my $php=0;
my $mod=0;

foreach(@lines) {
    if (!$php) {
        if (/^\s*<IfModule\s+(mod_php.|php._module)/) {
            $php++;
        } else {
            my $str=$_;
            s/^(\s*php_)/#$1/ && ($str ne $_) && $mod++;
        }
    } else {
        /^\s*<IfModule\s/ && $php++;
        /^\s*<\/IfModule/ && $php--;
    }
    push(@newlines,$_);
}

$mod || exit;

open(FILE, ">$fname") || die "Write error";
print FILE @newlines;
close(FILE);

print "$fname converted.\n"

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.