【问题标题】:Apache redirects sitemap.xml to error componentApache 将 sitemap.xml 重定向到错误组件
【发布时间】:2017-07-02 11:35:33
【问题描述】:

这是我的 Angular 路由器配置:

const appRoutes: Routes = [
{ path: 'home', component: HomeComponent,
data: {
  animation: {
    value: 'home',
  }
}
},
{ path: 'about',  component: AboutComponent,
data: {
  animation: {
    value: 'about',
  }
}
},
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: '**', component: ErrorComponent }
];

每次我尝试导航到 www.myapp.com/sitemap.xml 时,它都会匹配 ErrorComponent 并重定向到我的 404 页面。

如何配置 apache 服务器以阻止 sitemap.xml 转到 index.html?

以下是我在 .htaccess 文件中的重写规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

【问题讨论】:

  • 配置你的服务器not当路径是sitemap.xml时提供index.html
  • 如何在 .htaccess 文件中定位 sitemap.xml?
  • 我已将 .htaccess 代码添加到帖子中
  • 您还需要更改问题的文本及其标签。实际问题是关于 apache http 服务器和 .htaccess 文件,而不是关于 xml 和 angular。
  • 你能看到我现在要做什么吗?

标签: xml apache angular .htaccess


【解决方案1】:

我想通了。我只需要添加以下重写规则即可重定向到 sitemap.xml 文件。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^sitemap\.xml$ sitemap.xml [L]
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2011-08-06
    • 1970-01-01
    • 2015-03-19
    • 2011-07-07
    相关资源
    最近更新 更多