Mod_rewrite QSA confusion

Posted on 2010-01-04
Last Modified: 2012-05-08

I'm in need of a rewrite code, which I have, but it's not working as expected/needed.

What I need to do is rewrite


Which works, but also, it needs the ability to contiue this pattern further, so i could do
/index.php?var1=var1data&var2=var2data&var3=var3data etc...
giving me

Below is my existing code, I read that the QSA flag might be needed? But also, my example has predefined variable names, can it be done without knowing the variable names?

RewriteRule ^([^/]*)/$ /index.php?var1=$1

Open in new window

Question by:i-CONICA
    LVL 26

    Accepted Solution


    If the variable names are static / known tTry something along the following lines:

    #Skip the next 8 rules if a Request for a Real directory
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)/$    -  [S=8]

    RewriteRule ^([^/]*)/$                         /index.php?var1=$1 [L]
    RewriteRule ^([^/]*)/([^/]*)/$             /index.php?var1=$1&var2=$2 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /index.php?var1=$1&var2=$2&var3=$3 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ /index.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5&var6=$6&var7=$7&var8=$8 [L]

    It's possible to specify the variable names as well, in the URL's, and adapt the rules accordingly.
    LVL 6

    Author Closing Comment

    Hi, Thanks for the response.

    I could use this but ideally, it'd work without knowing variable names in advance. Is that not possible?

    Thanks again.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now