I was tired of having to repeatedly create nginx rewrite rules for sites migrates from OLS or Apache, or for sites imported new or created first and then added WordPress later, the rewrite rule "/" to "index.php" kept causing issues... so I created a little shell script that uses the Enhance API to bulk check all sites, exclude service sites or other sites that do not need it, and if missing, prompts to create them for any that are missing. I thought I'd share it with Enhance admins or resellers here.
https://gist.github.com/presswizards/cbe6ba16b81f6a025afd539d9c17720f
I save it in /root/ and chmod 700 it, and then run it after imports or migrations.
It has a configuration at the top for your Enhance details:
API_KEY="your-access-token-here"
ORG_ID="your-enhance-org-id-admin-or-reseller"
API_BASE_URL="https://your-enhance.your-domain.com/api"
# Exclude list - all domains to skip (all Enhance service sites, etc.)
EXCLUDE_DOMAINS=(
"phpmyadmin.enhance.your-domain.com"
"webmail.enhance.your-domain.com"
"enhance.your-domain.com"
"server2.your-domain.com"
"non-wp-site-domain.com"
)
Example run:
# ./check-create-rewrites.sh
========================================
Enhance Webserver Rewrite Rule Checker
========================================
Using Organization ID: 8f27c1a9-1234-5678-9876-7a3b2ce92f6e
Fetching all websites...
Found 22 websites. Checking rewrite rules...
✓ exampler.com - rewrite exists
✓ enhancetest.otherdomain.com - rewrite exists
✓ otherdomain2.com - rewrite exists
✓ examplebakery.com - rewrite exists
✓ oldyeller.otherdomain.com - rewrite exists
✓ nick.otherdomain.com - rewrite exists
✓ hellocity.example.com - rewrite exists
⊝ enhance.example.com - excluded (service site)
✓ john.otherdomain.com - rewrite exists
✓ course1.example.com - rewrite exists
⊝ zipper.example.com - excluded (service site)
✓ example.com - rewrite exists
✓ otherdomain.com - rewrite exists
✓ otherdomain3.com - rewrite exists
✓ otherdomain4.com - rewrite exists
✓ otherdomain5.com - rewrite exists
✓ otherdomain6.com - rewrite exists
✓ otherdomain7.com - rewrite exists
⊝ db.enhance.example.com - excluded (service site)
Websites missing rewrite rule:
- otherdomain8.com
- design.example.com
- myotherdomain.com
========================================
Summary
========================================
Total websites: 22
Excluded (service sites): 3
With rewrite rule: 16
Missing rewrite rule: 3
Do you want to create the missing rewrite rules? (y/n): y
Creating rewrite for: otherdomain8.com
✓ Rewrite rule created successfully for otherdomain8.com
Creating rewrite for: design.example.com
✓ Rewrite rule created successfully for design.example.com
Creating rewrite for: myotherdomain.com
✓ Rewrite rule created successfully for myotherdomain.com
========================================
All missing rewrite rules have been created!
========================================
Script completed!