Redirecting

Redirecting refers to directing web traffic from one URL to another within the same website. There are numerous ways to set up a URL redirect. The standard format is as follows:

Redirect 301 /old-page https://example.com/new-page

Command | status code | old page | new page

For more complex redirects, the format can look completely different:

RewriteRule ^old-page/?$ https://example.com/new-page [R=301,L]

Command | old page | new page | flags

The syntax for a redirect with parameters can also look completely different:

RewriteCond %{QUERY_STRING} id=123

Command | variable containing query string | value matching the query string

RewriteRule ^old-page https://example.com/new-page [R=301,L]

Command | old page | new page | flags

Commonly used flags in redirects are:

  • R=301 – defines the HTTP status code. 301 defines permanent redirects, 302 defines temporary redirects.
  • L (Last rule) – indicates that this line is the last one in the chain, after which, processing will end.
  • N (Next round) – indicates that a line should be processed again.
  • NC (No Case) – capitalisation should not be taken into account.
  • QSA (Query String Append) – the current query string should be preserved, while adding new parameters.
  • OR (OR Statement) – indicates that multiple conditions should be combined using OR-logic.
  • P (Proxy) – defines a redirect without changing the URL
  • NE (No Escape) – indicates that special symbols in a URL should not be converted into their coded form.
  • QSD (Query String Discard) – indicates that query strings should be discarded from the original URL