简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM