通过URL重写规则阻止WordPress后台目录重定向的问题
Let’s break down why your /quotes/wp-admin is redirecting to the root /wp-admin—the main culprit is the reverse redirect rule in your /quotes/.htaccess that’s sending non-static resource requests from /quotes/ back to the root, and it’s not excluding wp-admin paths. Here’s how to fix it step by step:
Step 1: Update /quotes/.htaccess
Your current rule redirects all non-static requests from /quotes/ to the root. We need to add exceptions for wp-admin (and related login paths) so those requests stay within the subdirectory.
Replace this section:
# Redirect any direct requests for "/quotes/<anything>" back to root # Except for static resources RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|webp|gif|svg|ttf|woff)$ RewriteRule (.*) /$1 [R=301,L]
With this modified version:
# Redirect any direct requests for "/quotes/<anything>" back to root # Except for static resources and wp-admin/wp-login paths RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|webp|gif|svg|ttf|woff)$ RewriteCond %{REQUEST_URI} !^/quotes/wp-admin/ RewriteCond %{REQUEST_URI} !^/quotes/wp-login\.php RewriteRule (.*) /$1 [R=301,L]
What this does:
- Adds two new
RewriteCondlines to exclude any requests starting with/quotes/wp-admin/or/quotes/wp-login.phpfrom the root redirect. - Keeps your original static resource exclusion intact so assets still load correctly.
Step 2: Verify Root .htaccess Rules
Your root .htaccess rules (language prefix routing and SSL redirect) shouldn’t interfere with direct /quotes/wp-admin requests—subdirectory .htaccess files take priority over root rules by default. Just ensure the WordPress rewrite block at the bottom doesn’t have any custom rules that might override subdirectory behavior (your current setup looks fine here).
Step 3: Clear Browser Cache
Since you’re using 301 permanent redirects, your browser might have cached the old redirect to /wp-admin. Clear your browser cache, or test in incognito mode to confirm the fix works immediately.
Bonus: Double-Check WordPress Site Settings
Make sure your /quotes/ WordPress site has the correct URLs set in Settings > General:
- WordPress Address (URL):
https://example.com/quotes - Site Address (URL):
https://example.com(matches your root rule for language prefix routing)
This ensures WordPress generates correct admin URLs without redirecting away from the subdirectory.
内容的提问来源于stack exchange,提问作者Waterfall

