Windows Server环境下修改子域名并配置旧域名路径重定向咨询
Hey there! Since you're not a Windows Server pro, let's walk through this clearly—no overly technical jargon where we can avoid it. Here's what you need to do:
DNS Setup (No Wildcard Needed!)
First, forget about wildcard DNS for this scenario. Wildcards are useful when you need all unknown subdomains (like random.ag.mydomain.com) to point somewhere, but you only have two specific subdomains to handle. Here's the step-by-step:
- Add the new subdomain record: In your DNS manager, create an A record (or CNAME, if your original
example.ag.mydomain.comuses a CNAME) forexample1.ag.mydomain.compointing to the same IP address as your existing Windows Server. - Keep the old subdomain record: Don't delete
example.ag.mydomain.comyet—you need it to handle the redirect traffic. Leave its DNS record as-is for now.
Configure the Redirect in IIS
Assuming you're using IIS (the standard web server for Windows Server), you have two solid options to set up the /wordpress path redirect:
Option 1: Direct Redirect for the WordPress Directory
If wordpress is a physical directory or virtual directory under your example.ag.mydomain.com site:
- Open IIS Manager, navigate to your site for
example.ag.mydomain.com. - Find the
wordpressdirectory, right-click it, and select Redirect. - In the "Redirect to" field, enter
https://example1.ag.mydomain.com/wordpress(usehttpif you don't have SSL set up).- If you want to redirect subpaths too (like
/wordpress/post-123to the same path on the new subdomain), check "Redirect all requests to exact destination" and change the target tohttps://example1.ag.mydomain.com/wordpress/$S$Q.
- If you want to redirect subpaths too (like
- Choose a redirect status code:
- Use 301 (Permanent Redirect) if this change is long-term (good for SEO).
- Use 302 (Temporary Redirect) if you might switch back later.
- Click Apply to save the settings.
Option 2: URL Rewrite Rule (More Flexible)
If you need finer control (or if you don't have a separate wordpress directory set up), use the IIS URL Rewrite module:
- First, make sure the URL Rewrite module is installed. If not, open IIS Manager > Web Platform Installer, search for "URL Rewrite", and install it.
- Go to your
example.ag.mydomain.comsite in IIS Manager, double-click URL Rewrite. - Click Add Rule(s) > Select Blank Rule > OK.
- Configure the rule:
- Name: Something descriptive like
Redirect WordPress Path to New Subdomain - Match URL:
- Pattern:
^wordpress(/.*)?$(this matches/wordpressand any subpaths under it) - Ignore case: Checked
- Pattern:
- Conditions:
- Click Add > Condition input:
{HTTP_HOST}> Pattern:^example\.ag\.mydomain\.com$(this ensures the rule only applies to the old subdomain)
- Click Add > Condition input:
- Action:
- Action type: Redirect
- Redirect URL:
https://example1.ag.mydomain.com/wordpress{R:1}(the{R:1}captures the subpath from the original request) - Redirect type: Permanent (301) or Temporary (302)
- Name: Something descriptive like
- Click Apply to save.
Final Checks
- Wait for DNS propagation: DNS changes can take anywhere from 5 minutes to a few hours to take effect globally. You can test with
nslookup example1.ag.mydomain.comin Command Prompt to confirm it resolves to your server's IP. - Test the redirect: Open a browser and visit
https://example.ag.mydomain.com/wordpress—it should automatically jump to the new subdomain's WordPress path. You can also usecurl -I https://example.ag.mydomain.com/wordpressin Command Prompt to check the response headers (look for a 301/302 status and the correctLocationheader).
内容的提问来源于stack exchange,提问作者Kevin Lupo

