remove query strings?

How to Remove Query Strings from URLs

Query strings are a way to pass data from one page to another in the URL. They are usually identified by a question mark (?) followed by a series of key-value pairs separated by an ampersand (&). While query strings can be useful, they can also cause issues with caching and duplicate content. In this post, I will explain how to remove query strings from URLs.

Method 1: Using .htaccess file

The .htaccess file is a configuration file used by Apache web servers to control the behavior of the server. To remove query strings using .htaccess, add the following code to the file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1? [R=301,L]

This code checks if there is a query string present in the URL and if so, redirects to the same URL without the query string. The 301 redirect code tells search engines that the page has moved permanently, and they should update their index accordingly.

Method 2: Using a Plugin

If you are using WordPress, there are several plugins available that can remove query strings from URLs. One such plugin is Query Strings Remover. After installing and activating the plugin, simply go to its settings page and enable the option to remove query strings.

Method 3: Removing Query Strings Manually

If you don't want to use a plugin or modify your .htaccess file, you can also remove query strings manually. Simply look for any links on your website that contain query strings and remove them. For example, if you have a link that looks like this:

<a href="">Link</a>

You can remove the query string like this:

<a href="">Link</a>

Keep in mind that this method can be time-consuming if you have a lot of links on your website.


Removing query strings from URLs can help improve the caching and indexing of your website. Whether you choose to use a plugin, modify your .htaccess file, or remove query strings manually, it's important to test your website thoroughly after making any changes to ensure everything is still functioning as expected.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]