WordPress站点旧域名内链301重定向至新域名问题求助
Hey there, let's get those inner page redirects sorted out—you're halfway there with the root domain working!
Why Your Current Rule Only Handles the Root
Your existing RewriteRule ^/?$ "https\:\/\/wsx\.com\/home-page\/" [R=301,L] works perfectly for the root domain (qaz.com), but it only matches URLs with no path after the domain. Any inner page like qaz.com/home-page/professional-theme/ doesn't trigger this rule, which is why those links aren't redirecting.
Solution 1: Adjust Your .htaccess Rules
We'll add two targeted rules to cover both the root domain and all inner pages. Here's the full code to drop into your .htaccess file:
RewriteEngine On # Redirect root domain (qaz.com) to wsx.com/home-page/ RewriteRule ^/?$ https://wsx.com/home-page/ [R=301,L] # Redirect all other pages from qaz.com to wsx.com, keeping their full path RewriteCond %{HTTP_HOST} ^qaz\.com$ [NC] RewriteRule ^(.*)$ https://wsx.com/$1 [R=301,L]
What Each Rule Does:
- First rule: Targets only the root path (either an empty string or just
/) and sends it straight towsx.com/home-page/—this preserves your existing root redirect behavior. - Second rule: Checks if the request comes from
qaz.com(theNCflag makes this case-insensitive), captures everything after the domain (like/home-page/professional-theme/), and appends that path towsx.com.
Critical Notes:
- Order matters: Place these rules before WordPress's default rewrite block (which starts with
# BEGIN WordPress). If you put them after, WordPress's internal routing might take over first. - Clear your cache: 301 redirects are cached heavily by browsers, so you might not see changes right away. Test in incognito mode or clear your browser cache to verify.
- HTTPS check: Ensure target URLs use
https://to avoid mixed-content errors if your new site uses SSL.
Solution 2: Use a WordPress Plugin (No Code Needed)
If you'd rather not edit .htaccess directly, the Redirection plugin makes managing these redirects straightforward:
- Install and activate the Redirection plugin from your WordPress dashboard's Plugin Directory.
- Head to Tools > Redirection to access the plugin settings.
- Add two separate redirects:
- For the root domain:
- Source URL:
^$(matches only the root path) - Target URL:
https://wsx.com/home-page/ - Redirect Type:
301 - Permanent
- Source URL:
- For all inner pages:
- Source URL:
^(.*)$(uses regex to capture every path) - Target URL:
https://wsx.com/$1(the$1pulls in the captured path from the source) - Under "Match", select "Regex"
- Redirect Type:
301 - Permanent
- Source URL:
- For the root domain:
- Save both redirects, and you're done!
Final Check
After setting up either solution, test a few URLs to confirm everything works:
qaz.com→ should redirect towsx.com/home-page/qaz.com/home-page/professional-theme/→ should redirect towsx.com/home-page/professional-theme/- Any other inner page on
qaz.comshould land on its exact counterpart onwsx.com
内容的提问来源于stack exchange,提问作者serversetup co

