【问题标题】:sitemap.xml URL is not getting redirected to new URLsitemap.xml URL 未重定向到新 URL
【发布时间】:2021-06-01 22:55:36
【问题描述】:

我在本地主机上的 magento2 中生成了一个 sitemap.xml 文件。以下是链接http://magento.local/sitemap.xml 现在我想使用 URL 重写将上面的 URL 重定向到 http://magento.local/pub/sitemap.xml。我已将 URL 重写创建为 shown in this image

但是http://magento.local/sitemap.xml URL 没有被重定向http://magento.local/pub/sitemap.xml。但是如果我删除原始的 sitemap.xml 文件,它会被重定向到新的 URL。有什么方法可以在不删除现有 sitemap.xml 的情况下重定向它?

另一种选择 我将以下规则添加到 .htaccess 文件中,它在本地运行良好,但在服务器上却失败了。 URL 没有被重定向

<IfModule mod_alias.c>
Redirect 301 /sitemap.xml  http://magento.local/pub/sitemap.xml
</IfModule>

【问题讨论】:

  • 我在 .htaccess 文件中添加了以下规则,它在本地工作正常,但在服务器上它不起作用 Redirect 301 /sitemap.xml magento.local/pub/sitemap.xml

标签: xml magento magento2


【解决方案1】:

根据URL Rewrites

URL 重写工具可让您更改与 产品、类别或 CMS 页面。

我相信您的 sitemap.xml 是位于磁盘上的物理文件,因此它不适用于 Url Rewrite。当您删除原始文件时,服务器会尝试将 URL 视为一个页面。您可以使用 nginx 重写规则进行重定向,参考here

【讨论】:

    【解决方案2】:

    在您的 htaccess 文件中,您需要粘贴此代码。它对我有用。

    RewriteCond %{HTTP_HOST} ^http://magento.local$
    
    RewriteRule ^sitemap.xml http://magento.local/pub/sitemap.xml
    

    【讨论】:

      猜你喜欢
      • 2011-08-06
      • 2017-06-19
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多