【问题标题】:Robots.txt file not showing due to Web.config file由于 Web.config 文件,Robots.txt 文件未显示
【发布时间】:2019-03-12 01:39:07
【问题描述】:

我正在尝试使用直接链接 (https://www.example.com/robots.txt) 访问我的 robots.txt 文件,但我不断收到 404 错误。我怀疑这与我的 web.config 文件有关,但我不完全确定。

这是我的 web.config 文件

<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
   <system.webServer>
    <rewrite>
        <rules>
            <!-- BEGIN rule TAG FOR HTTPS REDIRECT -->
             <rule name="Force HTTPS" enabled="true">
               <match url="(.*)" ignoreCase="false" />
               <conditions>
                 <add input="{HTTPS}" pattern="off" />
               </conditions>
               <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
             </rule>
             <!-- END rule TAG FOR HTTPS REDIRECT -->
            <rule name="Rewrite to index.php">
                <match url="index.php|images|test.php" />
                <action type="None" />
            </rule>
            <rule name="Rewrite CI Index">
                <match url=".*" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php/{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

而我的 robots.txt 文件很简单

用户代理:* 不允许: 网站地图:https://www.example.com/sitemap.xml

我在我的网络应用程序的根目录中添加了 robots.txt 文件。关于为什么它没有出现的任何想法。

谢谢

【问题讨论】:

    标签: php azure web-config robots.txt


    【解决方案1】:

    我试图重现您的问题,但未能获得404 状态码的结​​果。这是我的步骤如下。

    1. 我创建了一个新的WebApp并部署了一些文件,包括robots.txtindex.php(只有一个代码phpinfo();)和web.config,内容与您的相同。然后,我访问https://&lt;my webapp name&gt;.azurewebsites.net/robots.txt得到phpinfo()200响应,如下图。

    2. 我看到robots.txt url 已被您的以下第三条规则重写为重定向到index.php

      <rule name="Rewrite CI Index">
          <match url=".*" />
          <conditions>
              <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php/{R:0}" />
      </rule>
      
    3. 所以我更改了上面的规则,将txt 附加到pattern 尾部,如下所示,然后我查看了有效的robots.txt url。

      <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|txt" negate="true" />
      

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      相关资源
      最近更新 更多