Skip to content

Instantly share code, notes, and snippets.

@ThakurGumansingh
Created September 12, 2023 06:47
Show Gist options
  • Save ThakurGumansingh/bcccc1a0272009d5fc97e67f7a4a8b66 to your computer and use it in GitHub Desktop.
Save ThakurGumansingh/bcccc1a0272009d5fc97e67f7a4a8b66 to your computer and use it in GitHub Desktop.
This script will check for any htaccess present in wp folders and if exists, it will rename it and will create a new htaccess in root_dir with default rules and downloads core files.
#!/bin/bash
# Function to search and rename .htaccess files
search_and_rename_htaccess() {
local dir="$1"
if [ -f "$dir/.htaccess" ]; then
echo "Found .htaccess in $dir"
mv "$dir/.htaccess" "$dir/.htaccess-bak"
echo "Renamed to $dir/.htaccess-bak"
fi
}
# Function to create a new .htaccess file with WordPress code
create_new_htaccess() {
local dir="$1"
local code="# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress"
echo -e "$code" > "$dir/.htaccess"
echo "Created new .htaccess in $dir"
}
# Search and rename .htaccess in the root directory (public_html)
search_and_rename_htaccess "."
# Search and rename .htaccess in wp-content, wp-includes, and wp-admin directories
search_and_rename_htaccess "wp-content"
search_and_rename_htaccess "wp-includes"
search_and_rename_htaccess "wp-admin"
# Create a new .htaccess in the root directory (public_html) with WordPress code
create_new_htaccess "."
# Execute the 'wp core download --skip-content --force' command
wp core download --skip-content --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment