user3664594
user3664594

Reputation: 191

.htaccess redirect to http if url contains string

I'm trying to config my htaccess so that if a URL in my website contains Buy,Rent,Make-offer,Sold to redirect https requests to http

This is what I've tried with no luck

# Redirect other HTTPS requests to plain HTTP
RewriteCond %{HTTPS} on
RewriteRule ^(buy|rent|sold|make-offer)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

Can someone help me?

Upvotes: 0

Views: 1256

Answers (1)

TerryE
TerryE

Reputation: 10898

Your match pattern contains beginning and end of string anchors (^ and$) so will only match URLs which are //host/buy etc. If you want beginning with then drop the $ and if you want contains, then drop both. If you want "which contains the word buy ..." then use

  RewriteRule \b(buy|rent|sold|make-offer)\b http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

etc. Hope this helps.

Upvotes: 1

Related Questions