How to remove query strings from URL using .htaccess

A query string is the stuff after the question mark in URLs.

Remove query string makes you URL more readable and easier to share on social media.

RewriteEngine On
RewriteCond %{QUERY_STRING} !="" #if there is a query string
RewriteCond %{QUERY_STRING} !^p=.* #allow wordpress
RewriteCond %{REQUEST_URI} !^/wp-admin.* # allow wordpress admin
RewriteRule ^(.*)$ /$1? [R=301,L] 

If you are using Wordpress, put it before the line # BEGIN Wordpress in .htaccess.