• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

177
Vistas
Apache - RewriteCond/RewriteRule for URL in HTTPS and with a specific parameter

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).

  1. Example 1: nothing should be done because the url is being accessed in http

    Original URL: http://example.com
    Final URL: http://example.com

  2. Example 2: Apache needs to redirect to https://example.com?parameterName=parameterValue

    Original URL: https://example.com
    Final URL: https://example.com?parameterName=parameterValue

  3. 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

about 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The code below did what I needed:

RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !.*parameterName.*
RewriteRule /myapplicationpath?(.*) /myapplicationpath?parameterName=parameterValue&%{QUERY_STRING} [R]
about 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda