A rewrite lets a visitor use a short address while the server loads a different file internally. Unlike an external redirect, it does not normally change the address in the browser. Use it for a specific routing requirement, and preserve the rules generated by your CMS.
These instructions apply where the web server supports Apache-compatible .htaccess rules. Native NGINX does not read this file. A CDN or reverse proxy can also affect the request seen by the origin server. Keep File Manager or SFTP available so you can restore the previous file if a rule prevents browser access.
IN THIS ARTICLE
01 Create a specific rewrite
- Download a copy of the existing
.htaccessfrom the website's document root. In File Manager, enable display of hidden files if necessary. - Confirm that the target file exists. In this example,
/sitemapwill load/files/folder/sitemap.html. These are illustrative paths; change them for your site. - Place the specific rule before a CMS catch-all block, outside any section that the CMS says it manages. Do not replace the whole file.
RewriteEngine On
RewriteRule ^sitemap/?$ files/folder/sitemap.html [END]
This Apache 2.4 example matches only the requested path with an optional trailing slash. In a document-root .htaccess, the pattern does not start with a slash. If your compatible web server supports only the usual [L] flag, confirm its behavior with support before adapting the example.
02 Check routing and public links
- Open
https://example.com/sitemapand verify the expected content while the address remains unchanged. - Test unrelated pages and an address that should return 404. A broad rule should not accidentally turn missing pages into a successful home page response.
- If both the short and original file URLs remain public, choose a canonical URL in your application or SEO configuration. Use a deliberate redirect only when you intend the browser to move.
How do I recover from a rewrite error or redirect loop?
Restore the saved file if you receive an immediate 500 response, then inspect the error log. Check rewrite support, spelling, the rule order and the real target path. Redirect loops often involve a CMS rule or HTTPS/canonical-host redirect in another layer. Test one change at a time and clear only the relevant cache after fixing the cause.