Reputation: 6812
I'm using Angular 2 and just added a robots.txt to the root of my dist folder on production (for SEO purposes)
But the file isn't accessible since the url https://myrandomsite.com/robots.txt
just redirects to my PageNotFoundComponent because of how my routing is setup.
How can I allow robots.txt to be accessed "normally" and prevent my Angular 2 routing config to trigger?
Edit: I am using Angular2 frontend with a Firebase backend.
Upvotes: 0
Views: 2838
Reputation: 16917
That's no Angular problem, its one of your webserver.
Your webserver shouldn't redirect an URL to an existing file back to /index.html
.
See this IIS example configuration for redirecting with rules:
<rule name="AngularJS" enabled="false" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
IIS won't redirect if its a file, directory or URL starts with /api
!
UPDATE
Using firebase you should read this: https://firebase.google.com/docs/hosting/url-redirects-rewrites
Upvotes: 1