-
-
Save iPublicis/e8d0aea0de487813595fd0c416e4e3f6 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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