Skip to content

Instantly share code, notes, and snippets.

@Rud5G
Forked from colinmollenhour/buildhtaccess.sh
Created June 5, 2012 22:34
Show Gist options
  • Save Rud5G/2878564 to your computer and use it in GitHub Desktop.
Save Rud5G/2878564 to your computer and use it in GitHub Desktop.
.htaccess combiner
#!/bin/bash
# Author: Colin Mollenhour
#
# Usage: Run from the webroot, .htaccess-combined will be created.
dest='.htaccess-combined'
pwd=`pwd`
echo -n "" > $dest
while read -r file; do
loc=`dirname $file`
if [[ "$loc" =~ '^\./downloader/pearlib/\w+' ]]; then continue; fi
if [[ "$loc" = "." ]]; then
dir=$pwd
else
dir="$pwd/${loc#*/}"
fi
echo "<Directory $dir >" >> $dest
cat $file | sed 's/^/ /' | awk 1 >> $dest
echo -e "</Directory>\n" >> $dest
done < <(find -L . -name \.htaccess -type f | awk '{ print length, $0 }' | sort -n | awk '{$1=""; print $0}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment