I was wondering how can I rewrite the following URL below using mod_rewrite? And is there a online tutorial that explains mod_rewrite for dummies?
How can I rewrite this
You have a couple options for this, depending on how you want it to work.
The simplest way to redirect one file to another is to simply use the Redirect
directive:
Redirect /sitemap.php http://www.example.com/sitemap.xml
This will do a 302 redirect by default, but you can change it to a 301 by adding the status code as a first parameter, i.e.:
Redirect 301 /sitemap.php http://www.example.com/sitemap.xml
In both cases, this will result in a round trip back to the browser, so the address bar will change to show the new sitemap.xml
filename. If you don't want that, you can use the RewriteRule
directive:
RewriteRule ^sitemap.php$ /sitemap.xml [L]
Note that this is how you would write the rule from what is called a "per-dir context" which just means that the rule is being written from within either a .htaccess
file, or from a
block. If you're writing it from your main config, then you would need a leading slash (i.e. ^/sitemap.php$
) to show that you mean for the rule to match from the document root.