django - Azurewebsite django URL 重写另一个应用程序

标签 django wordpress azure azure-web-app-service

我已经在 Azure 网站中安装了 wordpress,它主要运行 Django。我已在应用程序设置中将应用程序设置为/blog 到/site/wwwroot/blog。

但是 web.config 不提供 URL www.example.com/blog,而是抛出 404 错误。

这是 web.config,您能否建议如何禁用 www.example.com/blog 的重写

<?xml version="1.0"?>
<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <appSettings>
    <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\python.exe" />
    <add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" />
    <add key="PYTHONPATH" value="D:\home\site\wwwroot" />

    <!--
    <add key="WSGI_PTVSD_SECRET" value="" />
    -->
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <!-- Required for websockets. -->
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="Python340_via_FastCGI" />
      <add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
      <!-- Uncomment the following handler to enable remote debugging. -->
      <!--
      <add name="ptvsd" path="ptvsd" verb="*" resourceType="Unspecified" type="Microsoft.PythonTools.Debugger.WebSocketProxy, Microsoft.PythonTools.WebRole"/>
      -->
      <!-- <clear/>
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
      -->
    </handlers>
    <rewrite>
      <rules>
        <!-- Uncomment the following rule to enable remote debugging. -->
        <!--
        <rule name="ptvsd" enabled="true" stopProcessing="true">
          <match url="^ptvsd(/.*)?$"/>
        </rule>
        -->
        <rule name="Static Files" stopProcessing="true">
          <conditions>
            <add input="true" pattern="false" />
          </conditions>
        </rule>
        <rule name="Configure Python" stopProcessing="true">
          <match url="(.*)" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
    <staticContent>
           <clientCache cacheControlMaxAge ="7.00:00:00" cacheControlMode="UseMaxAge" />
    </staticContent>
  </system.webServer>
</configuration>

最佳答案

根据您的描述,建议您尝试在规则中添加不匹配条件。

如果url的目标是blob文件夹,则不会被重写。

更多详细信息,您可以引用下面的配置。

<rule name="Configure Python" stopProcessing="true">
  <match url="(.*)" ignoreCase="false" />
  <conditions>
    <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
     <add input="{URL}" pattern="^/blog/.*" ignoreCase="true" negate="true" />
  </conditions>
  <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>

结果如下:

enter image description here

关于django - Azurewebsite django URL 重写另一个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45343655/

相关文章:

python - Django 。通过 include 标签将数组传递给子模板

php - 在 PHP 插件中包含第三方库时避免类名冲突的模式?

database - Azure 表存储 (NoSQL) 中的单独表与一张大表

azure - 如何将包含基本身份验证的Azure API应用程序导入API管理

javascript - 如何读取Django中下拉菜单的内容?

python - 此字段为必填错误,但字段格式为

php - 对 WooCommerce 订单中按产品类别订购的产品数量求和

html - 我的 html/css 代码在 IE 和 firefox 中的兼容性

c# - 在 Azure Key Vault 上存储长字符串

python - 安排一个 python 脚本在网络服务器上运行