简体   繁体   English

IIS 10 个站点需要 URL 重写以更改 WordPress 子文件夹名称

[英]IIS 10 site needing URL Rewrite for changed WordPress subfolder name

I have a client with an ASP.NET MVC project running on IIS 10.我有一个在 IIS 10 上运行的 ASP.NET MVC 项目的客户。

In IIS 10 I have an Application setup under the site that points to a WordPress installation folder.在 IIS 10 中,我在指向 WordPress 安装文件夹的站点下设置了一个应用程序。 The alias was previously oldblog and has now changed to blog .别名以前是oldblog ,现在已更改为blog

The WordPress URI was requested to be changed so I need to permanently redirect requests to the old URI to the new one.要求更改 WordPress URI,因此我需要将对旧 URI 的请求永久重定向到新 URI。

Root ASP site: https://www.example.com/根 ASP 站点: https://www.example.com/

Old WP URI: https://www.example.com/oldblog/旧 WP URI: https://www.example.com/oldblog/

New WP URI: https://www.example.com/blog/新的 WP URI: https://www.example.com/blog/

The following rule only partially works.以下规则仅部分有效。 oldblog does get rewritten to blog , but the rest of the URI is unpredictable/inconsistent. oldblog确实被重写为blog ,但是 URI 的 rest 是不可预测的/不一致的。

  <rule name="Rewrite /oldblog to /blog" stopProcessing="true">
    <match url="^oldblog(.*)$" ignoreCase="true" />
    <action type="Redirect" url="https://www.example.com/blog/{R:1}" redirectType="Permanent" />
  </rule>

I need to rewrite all requests to /oldblog/* to /blog/* - regardless of the full URI/querystring, I only want to rewrite oldblog to blog我需要将对 /oldblog/* 的所有请求重写为 /blog/* - 不管完整的 URI/querystring,我只想将oldblog重写为blog

/oldblog/  =>  /blog/
/oldblog/category/somecategory/  =>  /blog/category/somecategory/

I would suggest you try to make tests with the URL Rewrite rule below could help you redirect from URLs below.我建议您尝试使用下面的 URL 重写规则进行测试可以帮助您从下面的 URL 重定向。

/oldblog/  =>  /blog/
/oldblog/category/somecategory/  =>  /blog/category/somecategory/

Sample Rule样本规则

<rewrite>
            <rules>
                <clear />
            <rule name="Rule-3" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                            <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                                <add input="{HTTP_HOST}" pattern="example.com" />
                                <add input="{REQUEST_URI}" pattern="/oldblog(.*)|/oldblog" />
                            </conditions>
                            <action type="Redirect" url="/blog{C:1}" />
                    </rule>
            </rules>
</rewrite>

Test Result测试结果

在此处输入图像描述

Further, you could modify the rule above as per your own requirements.此外,您可以根据自己的要求修改上述规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM