Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

445
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?

9 months 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]
9 months ago · Santiago Trujillo Report
Answer question
Find remote jobs