walolinux
walolinux

Reputation: 551

Apache2 htaccess redirection too many redirects

I am trying to create an apache2 .htaccess redirection. I want to redirect this:

http://www.mywebsite.com/category/books to http://www.mywebsite.com/category/books/?fwp_categories=books

I have tried to do this, but i am getting a 'too many redirects' error:

RewriteRule ^category/(.*) http://www.mywebsite.com/category/$1?fwp_categories=$1 [R=301,L]

What am i doing wrong?

Thank you very much.

Upvotes: 1

Views: 73

Answers (1)

anubhava
anubhava

Reputation: 784928

You need a RewriteCond before this rule to prevent adding query parameter when it is already there:

RewriteCond %{QUERY_STRING} !(^|&)fwp_categories= [NC]
RewriteRule ^(category)/(.*?)/?$ /$1/$2?fwp_categories=$2 [R=301,L,NC,NE]

Make sure to clear your browser cache before testing this rule.

Upvotes: 1

Related Questions