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
According to URL Rewrites
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
In your htaccess file you need to paste this code. It works for me.