Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
.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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!