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

Azure环境下web.config实现WordPress指定URL重定向的技术问询

Fixing the URL Redirect for Your WordPress Site on Azure (web.config)

Got it, let's break down why your current rewrite rule isn't working and get that redirect sorted properly for both example.com and www.example.com.

Why Your Existing Rule Fails

IIS's URL Rewrite module matches against the decoded request path—meaning it converts URL-encoded characters like %E4 back to their actual Unicode equivalents (in this case, ä) before checking the rule. Your current rule uses encoded characters (%E4) and incorrect escaping, so it never matches the actual request path.

Additionally, the + character is a special regex symbol (it means "match one or more of the previous character"), so you need to escape it with \+ to match the literal + in your old URL.

The Correct web.config Rule

Here's the rule that will handle both the example.com and www.example.com domains, and properly match your old URL:

<rule name="Redirect Vad+är+Vårdskap Page" stopProcessing="true">
    <!-- Match the decoded path: Vad+är+Vårdskap__1053.html -->
    <match url="^Vad\+är\+Vårdskap__1053\.html$" ignoreCase="true" />
    <!-- Ensure we only redirect requests to example.com or www.example.com -->
    <conditions>
        <add input="{HTTP_HOST}" pattern="^(www\.)?example\.com$" />
    </conditions>
    <!-- Permanent 301 redirect to the new URL -->
    <action type="Redirect" url="/what-is-welcoming/" redirectType="Permanent" />
</rule>

Alternative: Unicode Escape for Special Characters

If you're worried about server character encoding issues (unlikely on Azure, but safe to use), you can replace the ä characters with their Unicode regex escape sequences (\u00E4):

<rule name="Redirect Vad+är+Vårdskap Page" stopProcessing="true">
    <match url="^Vad\+\u00E4r\+V\u00E4rdskap__1053\.html$" ignoreCase="true" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^(www\.)?example\.com$" />
    </conditions>
    <action type="Redirect" url="/what-is-welcoming/" redirectType="Permanent" />
</rule>

How to Test & Verify

  1. Save the updated web.config file in your WordPress root directory on Azure.
  2. IIS should pick up the change automatically, but you can restart your App Service instance to be safe.
  3. Test both:
    • http://example.com/Vad+%E4r+V%E4rdskap__1053.html
    • http://www.example.com/Vad+%E4r+V%E4rdskap__1053.html
      Both should redirect permanently to http://[your-domain]/what-is-welcoming/.

内容的提问来源于stack exchange,提问作者Emil Jönsson

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:42:56