# Htaccess rewriting rule depending on variable amount

**URL:** <https://forum.kirupa.com/t/htaccess-rewriting-rule-depending-on-variable-amount/327656>\
**Category:** Uncategorized\
**Created:** [March 17, 2012, 12:06am UTC](https://forum.kirupa.com/t/htaccess-rewriting-rule-depending-on-variable-amount/327656 "2012-03-17T00:06:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeeto](https://avatars.discourse-cdn.com/v4/letter/z/e274bd/32.png) [@zeeto](https://forum.kirupa.com/u/zeeto)\
**Post date:** [March 17, 2012, 12:06am UTC](https://forum.kirupa.com/t/htaccess-rewriting-rule-depending-on-variable-amount/327656/1 "2012-03-17T00:06:38Z")

</div>

Hello,

I’m trying to change /a/b/c to /index.php?a=1&b=2&c=3

I’ve got the rule in my htaccess file:

```auto
RewriteRule ([^/]+)/([^/]+)/? /index2.php?main=$1&category=$2 [QSA]

```

But I can’t figure out how to make this rule flexible to various amount of variables.

So  
/a should rewrite to /index.php?a=1  
/a/b should rewrite to /index.php?a=1&b=2  
/a/b/c should rewrite to /index.php?a=1&b=2&c=3

hlep 🙂
