1

I have a query with regards to .htaccess and redirecting some things.

I currently have a site that requires sitewide HTTPS. This is done via the .htaccess file.

I require two things to be on HTTP however: /sage/ and /index.php?route=ebay/openbay.

I currently have the following in place for sage, and it works. There is no loop and the redirect works fine.

RewriteCond %{HTTP_HOST} ^(www\.)?site\.co\.uk$ [NC]
##check if https
RewriteCond %{HTTPS} on
## if so, redirect to http
RewriteRule ^/?(sage) http://www.site.co.uk%{REQUEST_URI} [L,R]
## happy days! it works!

RewriteCond %{HTTP_HOST} ^(www\.)?site\.co.uk$ [NC]
##lets check again but this time for any remaining http
RewriteCond %{HTTPS} off
##if so redirect it back to https, unless sage is at the start.
RewriteRule !^/?(sage) https://www.site.co.uk%{REQUEST_URI} [L,R]
##great, still ahve sitewide https except on sage, mission accomplished.

Now, I have the problem of the line with the query string.

This is what I have, and it is placed under the above code in the htaccess.

RewriteCond %{QUERY_STRING} route=ebay/openbay/ [NC]
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R]

RewriteCond %{QUERY_STRING} !route=ebay/openbay/
RewriteCond %{HTTPS} off
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R,NC,QSA]  

Not only does this work, it creates a redirect loop with this and sage. I'm not sure why and I'm a little stuck.

I originally took the idea from an old post: Redirect some url to https in .htaccess, hoping that I could just add the two strings in the brackets so (sage/index.php etc)

I'm at a bit of a loss now, so I think its time to ask the world for help.

1 Answer 1

2

You can try this, see if it avoids loop for you:

RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/sage/? [NC]
RewriteCond %{QUERY_STRING} !route=ebay/openbay/ [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/sage/? [NC,OR]
RewriteCond %{QUERY_STRING} route=ebay/openbay/ [NC]
RewriteRule ^(.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Sign up to request clarification or add additional context in comments.

1 Comment

This does indeed solve the loop that was being created, thank you.

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.