Redirect Old URLS In .htaccess
Frequently when our clients upgrade their website, they will need URLs from the old site mapped to the new site. So for example maybe they had this URL on the old server: http://acme.com/widgets/egonomic-widget-design Maybe there are many sites on the Internet that link to this URL so they don’t want it to return a 404 error. Instead they want it to redirect to the new address of the article at: http://acme.com/smallwidgets/designing-egonomic-widgets This can be accomplished with a simple rewrite rule in the .htaccess file like this: RewriteEngine On Rewriterule ^widgets\/egonomic-widget-design$ http://acme.com/smallwidgets/designing-egonomic-widgets [R=permanent,L] Note that the RewriteRule should be on one line in the file … not wrapped over two lines. The pattern for the rewrite rule is:
|
1 2 3 |
RewriteRule [source patter] [destination] [options] |
Also notice that in the source pattern we escaped the slash (/) with a backslash (\). This is necessary since the slash has special meaning in a regular expression. In the above