我使用的是角2,我只是在生产中将一个robots.txt添加到我的dist文件夹的根目录中(为了SEO目的)
但是文件是不可访问的,因为url https://myrandomsite.com/robots.txt只是重定向到我的PageNotFoundComponent,因为我的路由是如何设置的。
如何允许“正常”访问robots.txt,并防止触发角2路由配置?
编辑:,我使用的是带有Firebase后端的Angular2前端。
发布于 2017-02-22 05:55:43
这不是角度问题,它是你的网络服务器之一。
您的URL服务器不应该将URL重定向到现有文件,返回到/index.html。
请参阅此IIS示例配置,以便使用规则重定向:
<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>如果一个文件、目录或网址以/api开头,IIS不会重定向!
更新
使用firebase时,您应该阅读以下内容:https://firebase.google.com/docs/hosting/url-redirects-rewrites
https://stackoverflow.com/questions/42383501
复制相似问题