Redirects
A simple guide to understand and how to use redirects effectively on your websiteA redirect on the internet refers to the forwarding of one URL to another. Redirects are used to send users from one web page to another. They are useful for changing URL structures, moving content, or addressing security concerns. Below, you'll find descriptions of different types of redirects, their HTTP statuses, and guidance on when and why to use them.
Redirects are executed at the Edge using SiteBox Worker to maintain their efficiency and speed.
See also:
SiteBox Worker
Bespoke SiteBox Worker to further improve security of websites
Types of redirects
- 301 Moved Permanently – this type of redirect indicates that the page has been permanently moved to a new URL. Browsers and search engine crawlers redirect users to the new address and update their indexes accordingly. Use it when you are permanently moving content to a new URL, and the old URL will no longer exist. This helps maintain search engine rankings.
- 302 Found – this type of redirect indicates that the page has been temporarily moved to a different URL. Browsers redirect users, but search engine indexes are not updated. Use it when you are temporarily changing a page and plan to return to the original URL in the future.
- 303 See Other – this type of redirect indicates that the user should perform another action to get the requested page; often used in forms, where redirection occurs after submitting data.
- 307 Temporary Redirect – similar to a 302 redirect
but compliant with
HTTP/1.1
. It indicates that the page has been temporarily moved. - 308 Permanent Redirect – similar to a 301
redirect, it indicates a permanent move, but it follows
HTTP/1.1
standards.
Reasons for using redirects
Redirects are often used for various reasons such as:
- changing domain names or URL structures,
- consolidating multiple pages into one,
- directing users to updated page versions,
- redirecting users to localized versions of a page based on their location.
Remember that improper use of redirects can affect your website's search engine indexing and user experience. Always try to use the appropriate redirect type based on the context.
With redirects, you can manage your website's structure, guide users, and enhance their navigation experience.
Advanced redirects
With the SiteBox Dashboard, you have the flexibility to define redirects at different levels. You can set up redirects for an entire environment, meaning they will apply across all pages and domains associated with that environment. This is particularly useful when you want to implement global changes in your URL structure or redirect users from removed pages to new ones.
Alternatively, you can set up redirects for a single domain. This allows for greater precision and control, enabling you to manage redirects at the level of a specific page. For instance, you might want to redirect users from a specific page on one domain to a new page on the same domain.
Case sensitivity
When defining redirects, it's important to note that they can be either case-sensitive or case-insensitive. This means that the redirect rules can consider or ignore the case (uppercase or lowercase letters) of the URLs.
A case-sensitive redirect will treat URLs with different cases as distinct. For example, /Blog
and /blog
would be
considered different URLs and could be redirected to different targets.
On the other hand, a case-insensitive redirect will treat URLs with different cases as the same. For example, /Blog
and /blog
would be considered the same URL and would be redirected to the same target.
This feature provides flexibility in handling different user inputs, as users may not always enter URLs in the case you expect.
Query string preserving
Preserving query strings allows the redirect URL to keep the query string of the original request.
Preserving query strings means retaining the additional information appended to a URL after a question mark (?), which typically consists of key-value pairs. When a redirect occurs, maintaining the query string ensures that the redirected URL carries over the same parameters as the original request.
This is valuable for maintaining session data, tracking user activity, or passing specific information between web pages or applications.
Example:
// Input redirect
/blog/ => /insights/?sort=desc
// Results
/blog/?sort=asc => /insights/?sort=asc
/blog/?query=tutorial => /insights/?query=tutorial&sort=desc
Trailing slash
When defining redirects, handling trailing slashes (the /
at the end of URLs) can be a point of consideration. By
adding a redirect with a %
symbol at the end instead of a /
, you can enable support for both URLs with and without
the trailing slash.
// Input redirect
https://acme.com/contact-us% => https://acme.com/contact/
// Results
https://acme.com/contact-us => https://acme.com/contact/
https://acme.com/contact-us/ => https://acme.com/contact/
Splat redirect
The splat redirect is a powerful feature that allows you to capture the remaining part of a URL and use it in the target
URL. By replacing the end of a URL with *
, you can capture any segments of the URL that follow.
For example, a splat redirect could be set up as follows:
// Input redirect
/authors/* => /about-us/
// Results
/authors/jon-snow => /about-us/
/authors/daisy-williams => /about-us/
The matched value can be used in the redirect location with :splat
.
// Input redirect
/blog/* => /insights/:splat
// Results
/blog/my-article => /insights/my-article
/blog/2021/12/my-article => /insights/2021/12/my-article
Placeholder redirects
Placeholder redirects provide another level of flexibility by allowing you to name segments of your URLs. By using a
colon :
followed by a name (like :year
, :month
, or :slug
), you can capture specific segments of the URL and use
them in the target URL.
For example, a placeholder redirect could be set up as follows:
// Input redirect
/blog/:year/:month/:slug => /insights/:month/:year/:slug
// Results
/blog/2021/12/my-article => /insights/12/2021/my-article
Redirects management
By utilizing the SiteBox Dashboard, you can manage redirects for each environment. Redirects can be defined separately for each domain or for all of them simultaneously. All changes made to redirects will be visible on the website within 2-3 minutes after the last update.
See also the user guide:
Redirects management
Learn how to add, edit and delete redirect rules