Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
.htaccess to parent directory

I am trying forward /test/12 to test?var=12 using htaccess

I have set up my .htaccess file as follows:

RewriteEngine on
RewriteRule ^test/(.+)$ test?$1 [L]

Can somebody point me in the right direction?

Thanks

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^test/([a-zA-Z0-9|]+)/([^/]*)/(.*)$ test.php?var1=$1&var2=$2&var3=$3 [B,QSA]

[^/] means "any character that's not a slash". Naturally this means that "text" cannot contain any slashes, but your URL will be matched correctly.

Also note the [B] which is one of many options you can add to a rewrite rule. [B] means that any &s and some other characters will be escaped.

now in your test.php

print_r($_GET);

will output for url http://localhost/test/123/456/asdf:

Array
(
    [var1] => 123
    [var2] => 456
    [var3] => asdf
)
over 4 years ago · Santiago Trujillo Denunciar

0

My mistake was adding the .htaccess in the wrong directory. I should have added it in the parent directory, but I was adding ^test/(.+)$ test?$1 in the test directory.

I wanted to take the full query after the trailing slash in the url, so the rule I used in the parent directory was RewriteRule ^(.*)$ test.php?$1. This in turn caused a circular loop so I redirected to a directory within the parent so the final working rule that took the final part of the url string after the / and forwarded it as a variable to test.php?$1 looked like this.

RewriteRule ^(.*)$ test/test.php?$1

over 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda