Forum Moderators: phranque
# requests to 'support' should be secure
RewriteCond %{HTTPS} ^off$
RewriteRule ^support(.*) https://%{SERVER_NAME}/support$1 [L,R=301] # secure requests outside 'support' should revert to http
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{HTTPS} ^on$
# This next line *should* filter out requests to the support directory
RewriteCond %{REQUEST_URI}!^/support
# Have also tried ...
#RewriteCond $1!^/support
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] Unfortunately, secure requests to the 'support' directory are not being filtered out by this line:
RewriteCond %{REQUEST_URI}!^/support which creates an endless loop. Does anyone have any suggestion what I'm doing wrong?
This site is running a CMS system which has its own redirect after the lines above. I'll include those just in case it could be affecting things.
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] This is on Apache 2.2.3. Thanks for any help!
Matt
Be aware that using %{HTTPS} ^on$ doesn't work on all servers, and you might want to try %{SERVER_PORT} ^443$ instead. Also, using %{SERVER_NAME} instead of %{HTTP_HOST} may also be problematic if the server name is not the canonical domain.
Note that in .htaccess, while %{REQUEST_URI} may have the value "/secure", the value of $1 will be "secure" -- Note the difference in the leading slash.
Jim
I just tried it now in Safari and it get into the endless loop, but it was also showing each page as it redirected. It went something like this (I'm sorry I need to use example.com -- long story):
[example.com...]
http://example.com/index.php?q=support/page
http://example.com/support/page
And then back to the beginning again. Which makes me wonder if the friendly-urls stuff that is already there, courtesy of the CMS, is messing things up. Shouldn't it stop processing once it gets to the [L] directive?
Thanks
Matt
This function is not part of the code you posted above, but it is apparently what is interfering here.
Jim
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I'm just not sure how to make them all work happily together ... I tried changing the order but it didn't seem to make a difference.
If so, then you'll need to add another exclusion in the HTTPS-to-HTTP redirect rule, such as
RewriteCond %{REQUEST_URI}?%{QUERY_STRING} ^/index\.php\?q=support/
Jim