0

I have this code for my htaccess file:

RewriteEngine On

RewriteRule /([^/]+)?$ index.php?page=$1
RewriteRule /([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2
RewriteRule /([^/]+)/([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2&var2=$3

It works fine however when I print out the get array on index.php it ignores the first variable so i have to do something like spareslist.com/randomthing/page/var1/var2

How would I be able to use this without having to have a random variable before the others?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Yesterday
  • 561
  • 1
  • 15
  • 31

1 Answers1

1

What about using the ^ in RewriteRule? Like this:

RewriteEngine On

RewriteRule ^([^/]+)?$ index.php?page=$1
RewriteRule ^([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2&var2=$3
Tomas
  • 57,621
  • 49
  • 238
  • 373
  • 2
    If rule is placed in .htaccess then URL will have no leading slash when matching in RewriteRule pattern. – LazyOne Jul 23 '11 at 12:07
  • Yes, that could be the reason of his mistake! But he should also involve ^ character as I said. I editted my code to reflect your comment. – Tomas Jul 23 '11 at 12:55