DNN UrlRewrite ("DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules") 不在 web.config 上运行自定义重写规则 [英] DNN UrlRewrite ("DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules") does not run custom rewrite rule on web.config

查看:9
本文介绍了DNN UrlRewrite ("DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules") 不在 web.config 上运行自定义重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在托管在 Azure 应用服务中的 DNN 站点上,我们在 web.config 中设置了以下自定义规则:

<重写><规则><规则名称="代理" stopProcessing="true"><匹配 url="^base3/?(.*)"/><action type="Rewrite" url="https://(aws s3 托管的网站)/tx/{R:1}"/><服务器变量><set name="HTTP_ACCEPT_ENCODING" value=""/><set name="HTTP_X_ORIGINAL_HOST" value="{HTTP_HOST}"/><set name="HTTP_X_Blog" value="1"/></服务器变量></规则></规则>

我们还在 applicationHost.xdt

中设置了以下内容

<?xml version="1.0"?><配置xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"><system.webServer><代理 xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false"/><重写><允许的服务器变量><add name="HTTP_X_ORIGINAL_HOST" xdt:Transform="Insert" xdt:Locator="Match(name)"/><add name="HTTP_X_UNPROXIED_URL" xdt:Transform="Insert" xdt:Locator="Match(name)"/><add name="HTTP_ACCEPT_ENCODING" xdt:Transform="Insert" xdt:Locator="Match(name)"/><添加名称="HTTP_X_ORIGINAL_ACCEPT_ENCODING" xdt:Transform="Insert" xdt:Locator="Match(name)"/><add name="HTTP_X_Mischief" xdt:Transform="Insert" xdt:Locator="Match(name)"/><add name="HTTP_X_Blog" xdt:Transform="Insert" xdt:Locator="Match(name)"/></allowedServerVariables></重写></system.webServer></配置>

但是,当尝试导航到它时(

私人

关于url重写功能,原因是App Service集成的Web Server无法完全控制.您可以在另一个 post 中参考我的回答.

您可以使用应用程序网关来实现url重写功能.

On our DNN site hosted in an Azure app service, we have the following custom rule set on our web.config:

<rewrite>
      <rules>
               <rule name="Proxy" stopProcessing="true">
                    <match url="^base3/?(.*)" />
                    <action type="Rewrite" url="https://(a website hosted in aws s3)/tx/{R:1}" />
                    <serverVariables>
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                        <set name="HTTP_X_ORIGINAL_HOST" value="{HTTP_HOST}" />
                        <set name="HTTP_X_Blog" value="1" />
                    </serverVariables>
                </rule> 

      </rules>

We have also setup the following in our applicationHost.xdt

<?xml version="1.0"?>  
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
    <system.webServer>  
        <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />    
        <rewrite>
            <allowedServerVariables>
                <add name="HTTP_X_ORIGINAL_HOST" xdt:Transform="Insert" xdt:Locator="Match(name)"/>
                <add name="HTTP_X_UNPROXIED_URL" xdt:Transform="Insert" xdt:Locator="Match(name)"/>                
                <add name="HTTP_ACCEPT_ENCODING" xdt:Transform="Insert" xdt:Locator="Match(name)"/>
                <add name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" xdt:Transform="Insert" xdt:Locator="Match(name)"/>

                <add name="HTTP_X_Mischief" xdt:Transform="Insert" xdt:Locator="Match(name)"/>
                <add name="HTTP_X_Blog" xdt:Transform="Insert" xdt:Locator="Match(name)"/>

            </allowedServerVariables>
        </rewrite>
    </system.webServer>  
</configuration> 

However, when trying to navigate to it (https://(our azure webapp.com)/base3/index.html) we constantly get the error The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. which is confusing because this was the rewrite rule we have used on our other sites.

We even tried the same approach on a fresh app service and the rewrite rule above works just fine..

Trying to figure out what's wrong through heuristic analysis, on our web.config the rewrite rule now works if:

under <system.webServer> <modules runAllManagedModulesForAllRequests="true"> then commenting <add name="UrlRewrite" type="DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules" preCondition="managedHandler" />

However, the main site breaks now..

How do we implement a rewrite rule that works properly with DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules??

解决方案

UPDATE

 <configSections>
     <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter" />
 </configSections>
 ......
 <RewriterConfig>
    <Rules>
       <RewriterRule>
         <LookFor>^default/([0-9]+)/([_0-9a-z-]+)</LookFor>
         <SendTo>11.aspx?id={R:1}</SendTo>
       </RewriterRule>
    </Rules>
 </RewriterConfig>

PRIVIOUS

About the function of url rewrite, the reason is the Web Server integrated by App Service cannot have full control. You can refer my answer in another post .

You can use the Application Gateway to implement the url rewriting function.

这篇关于DNN UrlRewrite ("DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules") 不在 web.config 上运行自定义重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆