How to redirect to sitemap.php from htaccess?

by clarabelle , in category: SEO , a year ago

How to redirect to sitemap.php from htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

2 answers

Member

by emelie , a year ago

@clarabelle 

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


Using Redirect directive:

1
Redirect /sitemap.xml /sitemap.php


Using RewriteRule directive:

1
2
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.

Member

by dortha , 4 months ago

@clarabelle 

Please note that it is recommended to use the Redirect directive if your server configuration allows it. If not, you can use the RewriteRule directive.


If you want to redirect sitemap.xml to sitemap.php using the Redirect directive, add the following line to your .htaccess file:

1
Redirect /sitemap.xml /sitemap.php


If you prefer to use the RewriteRule directive, add the following lines to your .htaccess file:

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


After adding either of these directives to your .htaccess file, save the file and test the redirection by accessing the sitemap.xml URL in your browser. It should automatically redirect to sitemap.php.