I need to add a parameter to the URL if the URL is being accessed in https and only if the parameter doesnt already exists (I don't need to check the parameter value).
Example 1: nothing should be done because the url is being accessed in http
Original URL: http://example.com
Final URL: http://example.com
Example 2: Apache needs to redirect to https://example.com?parameterName=parameterValue
Original URL: https://example.com
Final URL: https://example.com?parameterName=parameterValue
Example 3: Nothing should be done because the url is in https and contains the parameter "parameterName" (this one is to prevent infinite loop)
Original URL: https://example.com?parameterName=parameterValue
Final URL: https://example.com?parameterName=parameterValue
What I've tried so far :
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^parameterName$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}%parameterName=parameterValue
Edit 1: If I remove the "RewriteCond %{HTTPS} on" condition it seems the rule is being executed. The parameters are not being appended correctly but at least the rule is being executed.
Now I need to understand why the rule is not being executed when in HTTPS.
Googling a bit I found some posts saying that the AllowOverride has to be changed to AllowOverride All.
I updated the line below in my httpd-conf file but the behaviour did not change:
From: AllowOverride None
To to AllowOverride All
The code below did what I needed:
RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !.*parameterName.*
RewriteRule /myapplicationpath?(.*) /myapplicationpath?parameterName=parameterValue&%{QUERY_STRING} [R]