• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Mod_rewrite QSA confusion

Hi,

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

/index.php?var1=var1data
to
/var1data/

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
/var1data/var2data/var3data/


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?

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

Open in new window

0
i-CONICA
Asked:
i-CONICA
1 Solution
 
arober11Commented:

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.
0
 
i-CONICAAuthor Commented:
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.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now