skip to Main Content

I have a sitemap.xml file generated in magento2 on localhost. Following is the link http://magento.local/sitemap.xml
Now i want to redirect above URL to http://magento.local/pub/sitemap.xml using URL rewrite. I have created URL Rewrite as
shown in this image

But http://magento.local/sitemap.xml URL is not getting redirected http://magento.local/pub/sitemap.xml. But if I delete original sitemap.xml file it gets redirected to new URL. Is there any way I can redirect it without deleting existing sitemap.xml?

Another option
I added the following rule to .htaccess file and it works fine on local, but on server it fails. URL is not getting redirected

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

2

Answers


  1. According to URL Rewrites

    The URL Rewrite tool lets you change any URL that is associated with a
    product, category, or CMS page.

    I believe your sitemap.xml is a physical file which is locate on the disk, then it won’t work with Url Rewrite. When you delete the original file, server will try to consider the URL as a page. You can do the redirection using nginx rewrite rule, refer here

    Login or Signup to reply.
  2. In your htaccess file you need to paste this code. It works for me.

    RewriteCond %{HTTP_HOST} ^http://magento.local$
    
    RewriteRule ^sitemap.xml http://magento.local/pub/sitemap.xml
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search