ilyeah
ilyeah

Reputation: 23

WordPress .htaccess how to remove get parametrs

I need to redirect form

http://example.com/category/news/?layout=grid&nav=load_more 

to

http://example.com/category/news/

how to do it?

Upvotes: 1

Views: 73

Answers (2)

Babak Habibi
Babak Habibi

Reputation: 1859

Like this

Redirect /category/news/?layout=grid&nav=load_more http://example.com/category/news/

Upvotes: 0

MrWhite
MrWhite

Reputation: 45829

In order to match the query string portion of the URL you need to use mod_rewrite and use a condition to match against the QUERY_STRING server variable.

For example, the following removes the query string from the example URL stated:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^layout=grid&nav=load_more$
RewriteRule ^category/news/$ /$0 [QSD,R,L]

This must go at the top of your .htaccess file, before any existing WordPress directives.

$0 is a backreference to the entire URL-path that is matched by the RewriteRule pattern (saves retyping the URL-path).

The QSD (Apache 2.4+) flag is required to discard the query string. However, if you are still on Apache 2.2 then you will need to append a ? to the end of the substitution instead:

RewriteRule ^category/news/$ /$0? [R,L]

Upvotes: 2

Related Questions