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

940
Views
Redirect with optional query string (.htaccess)

I have coded a small PHP-Script, with which I have something like a short url.

short.url/string

gets directed to

short.url/redirect.php?id=string

Code:

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(.+)$ ./redirect.php?id=$1

Some of these short URLs have query strings; unfortunately, I have difficulty combining query strings with the code above

short.url/string?query

should get directed to

short.url/redirect.php?id=string&q=query

How could I do that?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to use QSA (Query String Append) flag in your rule

QSA flag is used to combine both new and old query strings.

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(.+)$ ./redirect.php?id=$1 [QSA]
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!