0

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?

3
  • Useful information for this question is: What is the exact url you are testing this with? That is: Copy and paste the url here, and for privacy's sake replace the domain name with "example.com". Commented Jun 1, 2014 at 11:57
  • This will only and exactly match /buy, /rent, /sold and /make-offer. Is that what you really want to do? Commented Jun 1, 2014 at 11:58
  • So this is a sample url example.com/buy/1241-187-collins-st-melbourne-vic-3000 Commented Jun 1, 2014 at 12:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

This is a sample URL example.com/buy/1241-187-collins-st-melbourne-vic-3000 I have used your solution but it doesn't goto http
The QSA flag is not required here, but otherwise this should work. Have you enabled the RewriteEngine with RewriteEngine on? Is your .htaccess file in your document root?
this is what i have RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] RewriteRule \b(buy|rent|sold|make-offer)\b http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]
This is what I get when I switch the rules The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.
got it to work by changing the rules around thanks for the input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.