You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过URL重写规则阻止WordPress后台目录重定向的问题

Fix WordPress Subdirectory wp-admin Redirect Issue

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 RewriteCond lines to exclude any requests starting with /quotes/wp-admin/ or /quotes/wp-login.php from 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 18:57:35