Convert all htaccess files to httpd.conf directives


This post is for the Apache web server, I created a simple script that will do the job. You may use it in Wordpress or in many CMS, surely this script will be useful in a lot of situations. It will help you to increase the speed and security of your site. Requirements: root access.

#! /bin/bash
b=$(find $1 -name .htaccess)
for p in $b; do if [[ -s "$p" ]] ; then a=$(dirname $p); echo \<Directory \"$a\"\>; cat $p; echo; echo \</Directory\>; echo; fi; done

You only have to specify the website directory and it fill search for all .htaccess files in sub-directories, then it will print the directives for the httpd.conf file, you can invoke the script like this:

./ /var/www/html

Add the resulting configuration manually to httpd.conf and don't forget to add AllowOverride None to the root directory, in this way my website speed increased noticeably! Also security increased. Please notice that you may end with a duplicated entry for the base directory, so please check it carefully. I read that a hacked website may include malicious code in the .htaccess files, so please check the code before adding into the config file.