How to redirect to sitemap.php from htaccess?

by clarabelle , in category: SEO , 7 months ago

How to redirect to sitemap.php from htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer


by emelie , 6 months ago


To redirect to sitemap.php from .htaccess, you can use the Redirect or RewriteRule directive depending on your needs.

Using Redirect directive:

Redirect /sitemap.xml /sitemap.php

Using RewriteRule directive:

RewriteEngine On
RewriteRule ^sitemap.xml$ /sitemap.php [L,R=301]

Both of these directives will redirect requests for sitemap.xml to sitemap.php. The R=301 flag in the RewriteRule directive will also send a HTTP 301 status code to the browser, indicating that the redirect is permanent.

Make sure to test your redirection after adding the code to the .htaccess file.