Search code examples
iisadsenseapp-ads.txt

Forwarding "ads.txt" for AdSense while using https->https redirect(IIS:URL rewrite)


My website is hosted on a Microsoft IIS server. I have created a rule that forward all http requests to https and I am using "URL rewrite". As explained for example here: Link to tutorial

All the requests are getting forward correctly. My problem is that AdSense needs the static file "ads.txt" for identification. this file is not being forward and gets blocked and so - my site cannot be verified. If I check "http://blabla/ads.txt" -> the link is NOT available. If I check "https://blabla/ads.txt" -> the link is available.

Any ideas?

this is my web.config.

<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="https redirect" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Solution

  • Thanks Lex Li, (do not add "stopProcessing="true"" to the first rule) this is the working web.config

    <configuration>
    <system.webServer>
        <rewrite>
            <rules>
        <rule name="adstxtrule">
              <match url="ads\.txt" />
              <action type="Redirect" redirectType="Permanent" url="https://arbelsolutions.com/ads.txt"/>
            </rule>
        <rule name="https redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"  redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
    

    Edit I - following nrod remark, this version also works:

    <configuration>
        <system.webServer>
        <rewrite>
            <rules>
        <rule name="adstxtrule">
              <match url="http://www.arbelsolutions.com/ads.txt" />
               <action type="Redirect" redirectType="Permanent" url="https://arbelsolutions.com/ads.txt"/>
            </rule>
        <rule name="https redirect" stopProcessing="true">
                   <match url="(.*)" />
                    <conditions>
                       <add input="{HTTPS}" pattern="^OFF$" />
                     </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"  redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>