remove query string from end of URL using .htaccess

mod-rewrite, url

Solution

it's simple, just use:

RewriteCond %{QUERY_STRING}    "post_type=" [NC]
RewriteRule (.*)  /$1? [R=301,L]

If you are going add this to wordpress website, you need add it before any wordpress rules:

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

but after

RewriteBase /

Problem

I'm trying to remove string from the end of URL: For example i have a structure like this: ``` http://sitename.com/category/first-category-name/?post_type=question http://sitename.com/category/second-category-name/?post_type=question http://sitename.com/category/...-category-name/?post_type=question ``` I would like to remove `?post_type=question` from the end of URL. I found a lot of examples on stackoverflow, but no one works for me. Thank you.

Original source