Skip to content

Instantly share code, notes, and snippets.

@bcremer
Created January 5, 2017 07:35
Show Gist options
  • Save bcremer/38437c5b6609a4f5431f838319ae327e to your computer and use it in GitHub Desktop.
Save bcremer/38437c5b6609a4f5431f838319ae327e to your computer and use it in GitHub Desktop.
htaccess_to_vhost
#!/usr/bin/env bash
#
# Converts .htaccess files to vhost directory directives
#
# http://httpd.apache.org/docs/2.4/howto/htaccess.html#when
# You should avoid using .htaccess files completely if you have
# access to httpd main server config file. Using .htaccess files
# slows down your Apache http server. Any directive that you can
# include in a .htaccess file is better set in a Directory block,
# as it will have the same effect with better performance.
#
# The use of .htaccess files can be disabled completely by setting
# the AllowOverride directive to none
# AllowOverride None
set -o nounset
set -o errexit
set -o pipefail
find -type f -name ".htaccess" -print0 | while read -d $'\0' file
do
dir=$(dirname $(readlink -f "$file"))
echo "<Directory $dir>"
cat $file | sed "s/^/ /g"
echo "" # make sure we have a newline after the last statement
echo "</Directory>"
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment