Blog posts

The Ultimate Guide to Redirecting Query Parameters!

April 3, 2023
5 minutes
Url Redirection Management Screen

A redirect is a tool used by websites for “rerouting” or sending a visitor to an alternative webpage. An example of a redirect would be when you type “” in your web-browser, but are taken to a different website, like “”

URL redirects are an extremely common practice employed by webmasters and content managers to ensure visitors to their website are reaching their desired content.

When would I use a redirect?

  1. A page has been relocated within your site
    Let’s say your website has a page by the path “/t-shirts” – The “t-shirts” page has been a part of your website sitemap for years, and is one of your most frequently visited pages. Suddenly, you need to build out a more general page on your site that has t-shirts, and dress shirts. Your goal is to have the new page be accessible by a shorter, more general path, like “/shirts”. In this situation, you would want to use a URL redirect to ensure that traffic for the page “/t-shirts” is successfully rerouted to the new “/shirts” page of your website. Without a redirect in place, you could run the risk of visitors still accessing the old /t-shirts page, even though you want to drive all traffic to the new /shirts page. Due to the nature of SEO, it’s possible that there are many links throughout the Internet that still point visitors to the old URL, and it is the job of the URL redirect to ensure visitors still make it to the appropriate page.
  2. Your domain name is changing!
    Changing a website’s domain name is a drastic decision which must be handled with the utmost care. Let’s say your website has always been Due to a rebranding effort, you are changing your brand from “ABC” to “XYZ”, and thus your website’s URL will need to be adjusted to reflect the change. In this scenario, it would be critical that you 301 redirect all traffic requesting “” to the new and improved “”. Furthermore, you would want to ensure that all pages within the abc-brand website are also redirected, like being redirected to
  3. You have alternative domains that you wish to serve as “shortcuts” into your website
    It is a common practice for businesses to buy dozens of domain names that:
  • Are spelled similarly to their business name – consider “” that redirects to
  • Are variations of their name that visitors may otherwise know them as – consider “” that redirects to the main business website, “”
  • Are shortened, easily typed versions of the primary domain name – consider “” redirecting to “”. It is common to find this shorter, more memorable URL variation on physical advertisements because people are more likely to remember them. As such, a URL redirect would be used to reroute the alternative domain name to your primary domain name of your website.

How does a redirect actually work?

When you request a web-page from your browser, there is a server somewhere on the Internet that is receiving your request and responding with the appropriate content. Fundamentally, a redirect occurs when a web-server's response contains a special piece of data (an HTTP response header) instructing the browser to reroute the visitor to an alternative location.

The technical details aside, a browser works by requesting a URL and rendering the page that is returned by the website. If the website wishes the user to be redirected, the server will respond differently than if it was serving a page; it will send an extra piece of data indicating that the visitor should be redirected to a specified location.

Without going into too much of the technical details – a redirect is a behavior performed by a web-browser whenever it receives a response containing a flag (an HTTP header) to do so.

What are the types of redirects available?

301 Redirect

Commonly referred to as a “permanent” redirect.

Indicates to search-engines and web-browsers that the requested page has permanently relocated to a new location.

Note: permanent redirects are often cached by web-browsers like Chrome and Firefox. Therefore, it may be tricky to retroactively update a 301 redirects target location once it has been established. Any visitors who have already received the 301 redirect response for a URL will likely be served a cached response from their web-browser when visiting the same URL again.

Suggestion Only use a 301 redirect when you know that the target location will not change.

Common Uses

  • A 301 redirect is appropriate when a website is changing it’s domain name. In this scenario, the site should be 301 redirecting all traffic for it’s old domain name to the new website URL.
  • Another common use-case for a 301 redirect is for pages within your website that have been permanently moved to a new URL

302 Redirect

Commonly referred to as a “temporary” redirect.

Useful for general-purpose redirects within your website, where you do not want visitor’s to cache the redirect response permanently.

Suggestion Use 302 redirects for pages that have changed URL, but are subject to be updated in the future

Common Uses

  • A page is temporarily being moved to a new URL
  • Conditions where the destination location of the redirect is subject to change
  • Navigating the user away from a page during an error

307 Redirect

Uncommon due to legacy browser support

Used for technical scenarios when a visitor’s HTTP request method should be persisted when they are redirected. For example, if a user submits a form, the browser normally issues a POST request to the form’s action URL. If the server responds with a 302 redirect response, the client’s web-browser would typically issue a GET request when handling the redirect. However, if the server responds with a 307 redirect response, the client’s web-browser will POST request to the redirect destination. Please note, form-data is typically lost when redirecting via POST request.

When do I need a redirect?

The most common use-cases that would require a redirect are:

  1. Changing your domain name
  2. Restructuring website pathing, resulting in URL changes for content within your website
  3. URL shortening – having a shorter, more memorable alternative to your primary domain name.
  4. Sending traffic from additional/alternative domain names (Example: redirects to
  5. Sending traffic from your DNS zone apex / naked domain name to your “www” sub-domain (Example: 301 redirects to

Important considerations when redirecting a URL

  1. Ensure your URL supports HTTPS connections! Otherwise you may have visitors who are receiving broken links.
  2. When redirecting a specific path within your website, you may want to match paths based on a pattern or Regular Expression, as opposed to a single path.
  3. Seriously consider whether you should use a 301 or a 302, based on the information above.

When managing a website, it's common to end up with URLs that contain messy query string parameters. You may have links like "page.html?source=google&id=123" lingering around. Or perhaps your site architecture has changed and old parameter-based URLs need to redirect to new cleaner pages.

While query strings can serve a purpose, excessive use of parameters in URLs can create complications for navigation, SEO, and overall user experience. Luckily, there are techniques to redirect these URLs to clearer structures.

What are Query String Parameters?

Query string parameters are additional pieces of data appended to the end of a URL, starting with a question mark (?). They allow you to pass variables and values into a webpage.

For example, you may see a URL like this:

Here, "color=blue" and "size=large" are query string parameters that pass data to the page. The page could then use this data to customize the display, pulling the color and size values.

Query strings are commonly used for search filters, personalization, tracking, and more. They enable dynamic interactions without having to create separate pages.

Why Should You Redirect URLs with Query String Parameters?

Redirecting URLs with query string parameters enables a few unique use cases including:

  • Campaign tracking: If you are running paid advertising campaigns on a separate domain, redirecting the URLs with campaign tracking parameters (such as utm_source, utm_medium, utm_campaign) allows you to preserve the campaign attribution when users click through to your main website. This ensures you can properly track traffic sources and analyze campaign performance in analytics tools like Google Analytics while preserving the user experience.
  • URL cleanup: If your site URLs have changed, redirecting old query string links to new clean URLs improves the user experience. For example, redirecting "page.html?id=about" to "about-us" makes for a simpler URL that users can easily understand.
  • Testing parameters: For A/B tests, extra parameters are often added to identify the traffic source and steps taken by the user. You can strip these off by redirecting to a clean URL without the temporary parameters while still tracking the traffic source.
  • Required parameters: If a page needs specific query parameters to function properly, you can redirect URLs missing them. For example, redirecting "products" to "products?category=new" to default to the "new" category.
  • Changing parameter structure: Redirects allow you to alter the structure of query parameters, like changing "id" to "product_id".

At the end of the day, the goal of redirecting URLs with query string parameters is to avoid broken links and send users to the right page with the expected results.

Using .htaccess Redirects

The most common way to redirect URLs with query string parameters on an Apache server is by using .htaccess files. .htaccess provides a simple redirect syntax:

Redirect /old-url /new-url

After the directive “Redirect” you can specify an HTTP status code. Without specifying an HTTP status code, the redirect defaults to a 302 redirect. So, to create a 301 redirect, you can use the following syntax:

Redirect 301 /old-url /new-url

How to Redirect URLs with Query String Parameters Using .htaccess

For URLs with query strings, you can redirect based on parameter matches. For example:

Redirect 301 /page.html?id=about&type=old /about-us

This example redirects any “/page.html” URL with the query string parameters “id=about” and “type=old.” The URL can contain additional query string parameters as well. As long as it contains these two query string parameters, the page will be redirected to the defined redirect page “/about-us.”

When using .htaccess redirects, keep these notes in mind:

  • Use the full URLs including the domain, not just local page paths.
  • 301 redirects are permanent, 302 redirects are temporary.
  • Additional parameters can be passed through or appended to the new URL.
  • Test carefully, as redirects can cause infinite loops if configured incorrectly.

Regular Expression Matching

For more complex redirect scenarios, regular expressions can be used to precisely match and manipulate query string patterns with the RedirectMatch directive. For example:

RedirectMatch 301 "(.*).docx$" "$1.html"

This would redirect all Word documents with a .docx file type to HTML pages with the same name.

The key difference between RedirectMatch and Redirect is that RedirectMatch utilizes regex for pattern matching. It also supports back-references like $1 and $2 to capture groups from the regex pattern and insert them into the new redirect URL. For example:

RedirectMatch 301 "/file=(.*)" "/new-file?id=$1"

This captures the file parameter value to reuse in the redirected URL. You can use multiple capture groups and backreferences sequentially - (group1) (group2) - referred to as $1, $2.

With strategic regex, you can flexibly match legacy URL patterns and programmatically generate cleaner redirected URLs.

Is There an Easier Way to Redirect URLs with Query String Parameters?

As we've seen, redirecting URLs with query string parameters requires carefully crafted .htaccess rules and regex expressions. For most websites, implementing these redirects properly is crucial for a smooth user experience. However, managing complex redirects can become cumbersome over time.

This is where services like SiteDetour can help. SiteDetour provides a user-friendly platform for hosting and managing redirects at scale. With SiteDetour, you can:

  • Seamlessly create query parameter-based redirection rules through an intuitive interface.
  • Automatically enable SSL certificates for your redirects.
  • Access real-time traffic analytics to monitor redirect performance.
  • Integrate redirects through the developer API.

Rather than struggle with DIY redirect solutions, consider leveraging SiteDetour to offload the redirect hosting burden. Their reliable infrastructure and query string rule support makes redirect management simple. You can try SiteDetour for free to see how a complete redirect solution can help your website thrive.

Get Started With SiteDetour

Our team will happily walk you through our platform and pricing to find a solution that perfectly fits your agency’s unique needs. The best part? You can try SiteDetour and experience all its benefits absolutely free.