Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Luke Hook 45 posts 175 karma points c-trib
    Apr 12, 2019 @ 10:20
    Luke Hook
    0

    Robots.txt edit in CMS - URL rewrite to handle file extension?

    Hi guys,

    I'm building a site for a client who has quite specific requirements around being able to edit their Robots.txt file (amongst other things).

    I've been following this really handy article by glcheetham https://glcheetham.name/2016/10/02/robotstxt-umbraco/

    However I obviously come across issues when it comes to rewriting the URL to handle the file extension as UrlRewriting.config no longer exists.

    Does anybody know of an alternative way to do this or better yet an IIS Rewrite rule I can use instead that will achieve the same result as this.

    <add name="robots-rewrite" virtualUrl="^~/robots.txt" destinationUrl="~/robotstxt"/>
    

    Apologies if this a simple query, my rewrite skills are not the greatest :)

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Apr 12, 2019 @ 21:09
    Søren Gregersen
    1

    The rule would be something like

    <rule name="robots.txt">
      <match url="^robots.txt$"/>
      <action type="Rewrite" url="~/robotstxt" />
    </rule>
    

    The "^" in url means "start of input", and "$" is end of input. The url is everything between the first "/" and first "?" in the url. This will then match http://site.com/robots.txt, but not http://site.com/robots.txtandmore

    HTH :)

Please Sign in or register to post replies

Write your reply to:

Draft