Adriano
Adriano

Reputation: 58

htaccess rewrite rule removing get parameter

I have this kind of url:

http://www.example.com/activities?_activities=surf

What I'm trying to do is to get this other kind of url:

http://www.example.com/activities/surf

So what I need is just to remove ?_activities from url.

I tried to write some rewrite rule in htaccess but with no success.

Here what I tried:

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

What I'm wrong?

Upvotes: 0

Views: 88

Answers (1)

piet
piet

Reputation: 106

Using the QSD (query string discard) flag removes the query string:

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

Applied to
http://www.example.com/activities?_activities=surf
the output will be
http://www.example.com/activities/surf

Note to the various flags:

  • NC: non-case-sensitive
  • R: redirect, 301 means permanent redirect
  • L: last rule, if the rule matches, no further rules are being processed.

Upvotes: 1

Related Questions