Apache

From Unix Wiki
Jump to: navigation, search

mod_rewrite

Next example will rewrite http and https URL for 192.168.1.0/24 network.

# cat .htaccess
RewriteEngine on
RewriteCond %{SERVER_PORT} =443
RewriteCond %{HTTP:X-FORWARDED-FOR} ^192.168.1.
#RewriteCond %{REMOTE_ADDR} ^192.168.1.15$
RewriteRule ^(.*) https://test.example.com/$1 [R]

RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP:X-FORWARDED-FOR} ^192.168.1.
#RewriteCond %{REMOTE_ADDR} ^192.168.1.15$
RewriteRule ^(.*) http://test.example.com/$1 [R]

Get list of all indcluded files

PERL script to get list of all included files in apache configuration. Works recursively.

#!/usr/bin/perl

use strict;
use Cwd 'abs_path';

my $base = "/etc/httpd";
my $conf = "conf/httpd.conf";

sub getIncludes {
  my $file = abs_path(shift(@_));
  print $file, "\n";
  open my $fh, "< $file" or die "Error opening file $file: $!\n";
  while (<$fh>) {
    next if ( ! m|^\s*include\s*(\S+?)\s*$|i || m|^\s*#| );
    chomp;
    getIncludes("$1");
  }
  close $fh;
}

chdir $base;
getIncludes("$conf");

exit 0