Skip to content

Instantly share code, notes, and snippets.

@deadbok
Last active August 1, 2016 08:50
Show Gist options
  • Save deadbok/45a01eccb4a3f06d0b5d3c9841916793 to your computer and use it in GitHub Desktop.
Save deadbok/45a01eccb4a3f06d0b5d3c9841916793 to your computer and use it in GitHub Desktop.
Better .htaccess for WordPress on VestaCP
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
# Stop user enumeration
RewriteCond %{QUERY_STRING} author=d
RewriteRule ^ /? [L,R=301]
# Restrict access to PHP files from plugin and theme directories
#RewriteRule wp-content/themes/(.*\.php)$ - [R=404,L]
</IfModule>
# Deny directory listings
Options -Indexes
# Prevent execution of PHP files in the upload directory
<Files *.php>
Order allow,deny
Deny from all
</Files>
Hello.
This mail is just to inform you that your .htaccess files on $2 has been replaced.
Included is a log file of the process.
Have a nice day!
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# Reset the password of a specific WordPress user on all WordPress installations on a VestaCP setup.
#MIT License
#
#Copyright (c) 2016 Martin Bo Kristensen Grønholdt
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE
#An list of addresses to send the info.
EMAILS=([email protected])
#Wildcard pattern for entering all sites.
DIRS=($1/*/web/*/public_html)
#The time is now.
NOW=$(date +"%m_%d_%Y_%H_%M")
LOGFILE=wp-htaccess-log-$2-${NOW}.log
#WordPress user
WP_USER=admin
source config.sh
#http://stackoverflow.com/a/7633579
function template()
{
# usage: template file.tpl
while read -r line ; do
line=${line//\"/\\\"}
line=${line//\`/\\\`}
line=${line//\$/\\\$}
line=${line//\\\${/\${}
eval "echo \"$line\"";
done < ${1}
}
#http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself/3403786#3403786
# Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
exec > >(tee -i ${LOGFILE})
echo Dirs: ${DIRS[@]}
echo
for DIR in "${DIRS[@]}"
do
WP_CONF_FILE=$DIR/wp-config.php
echo Working directory: $DIR
echo ------------------------------------------------------------------------------------------------------------------
#Split the path by '/' to isolate user and domain
REL_PATH=$(echo "$DIR" | rev | cut -d"/" -f1-5 | rev)
DIR_PARTS=(${REL_PATH//\// })
DOMAIN=${DIR_PARTS[2]}
echo "Domain: $DOMAIN"
if [ -f $WP_CONF_FILE ];
then
echo "Installing new .htacces file in ${DIR}"
cp htaccess ${DIR}/.htaccess
echo "Installing new .htacces file in ${DIR}/wp-content"
# To tight!
rm ${DIR}/wp-content/.htaccess
#cp htaccess-no-php-exec ${DIR}/wp-content/.htaccess
echo "Installing new .htacces file in ${DIR}/wp-content/uploads"
cp htaccess-no-php-exec ${DIR}/wp-content/uploads/.htaccess
echo "Installing new .htacces file in ${DIR}/wp-includes"
# To tight!
rm ${DIR}/wp-content/.htaccess
# cp htaccess-no-php-exec ${DIR}/wp-includes/.htaccess
else
echo "$DIR contains no WordPress installation"
fi
echo
done
echo "Mailing log"
for EMAIL in "${EMAILS[@]}"
do
echo "Mailing: ${EMAIL}"
template htaccess_mail.txt | mutt -s "Installing new .htaccess files on $2" -a ${LOGFILE} -- ${EMAIL}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment