Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
.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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda