2

I've found a number of solutions on stackoverflow on rewriting urls with a variable number of variables. But wasn't able to find anything on the situation where these variables can occur in a variable order. In my case I've a page with 4 potential variables:

www.domain.com/page.php?a=var1&b=var2&c=var3&d=var4

I want my users to be able to access this as:

www.domain.com/page/var1/var2/var3/var4

So far I was able to do this with htaccess. But the problem is that not all the variables occur anytime. I want Url's like these be possible:

www.domain.com/page/var1/var2/var4
www.domain.com/page/var1/var4
www.domain.com/page/var1/var3
etc.

I think this is not possible with htaccess. But what would be the most elegant solution to use clean Url's on this one.

Hope anyone has any ideas...

Juvlius
  • 237
  • 1
  • 2
  • 6

2 Answers2

2

I think your best shot would be to change slightly the design of your "pretty" URL. So for the URL

www.domain.com/page.php?a=var1&b=var2&c=var3&d=var4  

you'd be better off having the following

www.domain.com/page/a/var1/b/var2/c/var3/d/var4  

or even

www.domain.com/page/a=var1/b=var2/c=var3/d=var4

How otherwise would your script know that e.g. b and c have been omitted?

Havelock
  • 6,913
  • 4
  • 34
  • 42
1

A very fine, clean URL already is:

www.domain.com/page.php?a=var1&b=var2&c=var3&d=var4

If you don't think so (I like these URLs, they are very semantic), and if you now need to preserve information about which parameter is what, you just need to keep the names:

www.domain.com/page/a/var1/b/var2/c/var3/d/var4

works perfectly with .htaccess.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • bummer.. you did beat me to it :) – Havelock Sep 28 '12 at 12:54
  • Oké, thanks both. I was hoping for something even cleaner, but this will work as well. – Juvlius Sep 28 '12 at 16:58
  • @Juvlius: Then you should ask that way. There is nothing wrong with making own suggestions how to solve in the question already and you will get better answers, too. – hakre Sep 28 '12 at 17:00