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 8 posts 78 karma points
    1 week ago
    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 234 posts 977 karma points c-trib
    1 week ago
    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