title: Next.js simple rewrite not working when trying to rewrite from /robots.txt
body: <p>I am trying to create a dynamic robots.txt file in my next.js app. The api route solution suggested by @juliomalves works well:
  <a href="https://stackoverflow.com/questions/67387483/generating-a-dynamic-robots-txt-file-in-a-next-js-app">Generating a dynamic /robots.txt file in a Next.js app</a></p>
  <p>Until the rewrite, which returns a '404 Not Found' for me. What am I not seeing?!</p>
  <p><strong>Rewrite logic in next.config.js, based on next.js docs:</strong></p>
  <pre><code>async rewrites() {
          return [
              {
                  source: `/robots.txt`,
                  destination: `/api/robots`
              }
          ];
      },
  </code></pre>
  <p><strong>'pages/api/robots'</strong></p>
  <pre><code>import React from &quot;react&quot;;
  import { GetServerSideProps } from &quot;next&quot;;
  
  const rootUrl = process.env.PUBLIC_URL
  
  const robotsResponse = &quot;content&quot;
  
  export const getServerSideProps : GetServerSideProps = async (context) =&gt; {
      const { res } = context;
  
      res.write(robotsResponse);
      res.end();
  
      return(
          &lt;&gt;{res}&lt;/&gt;
      );
  };
  
  
  export default getServerSideProps;
  </code></pre>
  <p>But when I access '/robots.txt', I receive a '404 Not Found'. Any ideas anyone?</p>