HTTP URL Redirect
A RewriteRule is one way to redirect a request for a URL to a different page, which is called a URL redirect or URL forwarding. It is the recommended way to do a URL redirect for static web pages.
If you move a site, directory or one or more web pages you should create a URL redirect in the old location to automatically send users to the new location. To potentially preserve the page rank of those pages, it is recommended to create URL redirects on a one-to-one page-for-page basis (see Google Webmaster Central Help on "Moving Your Site"). In addition, the instructions in Google Webmaster Tools "Site configuration" - "Change of address" should be followed.
Although this also works for dynamically-generated pages it requires knowledge on how to code regular expressions.
When generating HTML with a program or server-side scripting, the language probably has an API to send the proper HTTP headers.
- URL Redirect in ASP .NET
- URL Redirect in Java
- URL Redirect in JSP
- URL Redirect in Perl CGI
- URL Redirect in PHP
- URL Redirect in Ruby on Rails
Regular Expression Metacharacters
Any regular expression metacharacters in the RewriteRule must be escaped with a backslash (\). These metacharacters that need to be escaped include:
- \ - backslash
- ^ - caret
- $ - dollar sign
- . - period (dot)
- | - vertical bar (pipe)
- ? - question mark
- * - asterisk (star)
- + - plus sign
- ( and ) - parentheses
- [ and ] - square brackets
See the URL Redirect Examples below for an example.