PHP site / htaccess for clean URLs / sort by color/price etc issue

Associate
Joined
15 Feb 2006
Posts
1,872
Location
hell
Hi

I'm trying to build a php driven site with rewritten URLs. I have the done the basics and have rewritten URLs working on my site.

The problem I now have is that I want to sort my data, and since you have to use the query string to do this, you end up having a very large htaccess file (which you have to write manually).

Example

I have a page listing 9 products out of 100 products.

I have a sorting navigation where users can select products by Gender, Type, Price, Colour. Users can also press "View All" to see all 100 products.

The URL that displays 9 products is:

www.domain.com/product

When the user clicks "Mens" from the sorting navigation, the URL changes to www.domain.com/product/gender/mens and my htaccess file instructs that "mens" should be considered part of the gender variable in the query string.

Now if on the mens product page, they press "color = red" the URL changes to

www.domain.com/product/gender/mens/color/red and htaccess file instructs that color variable should be red.

My PHP page has the relevant queries set up that see if color/gender etc is set().

now the issue is, to my (basic) knowledge, you have to rewrite regular expressions in the correct order. So for example i have to have both: color/([^/]+)/gender([^/]+) and gender([^/]+)/color([^/]+) set up in my htaccess to drop the words in the correct variables.

This gets extremely complex if you throw other sorts into the mix - depending on the user journey, the URL is different

www.domain.com/color/red/gender/ladies/speed/fast
www.domain.com/speed/fast/color/red/gender/ladies
www.domain.com/gender/ladies/color/red/speed/fast etc etc all have to be accounted for in the htaccess.

BTW
I'm using a script that takes the current URL of my page, and appends the relevant /gender etc onto the end for the creation of links on my page.

Can anyone assist me with this dilema?

I want to make the sort work like www.asos.com (clothes shopping site). YOu can sort by various things - they don't use rewritten URLs though so it's a LOT easier?
 
Hi

Yes I will be using queries to do the actual sort, but I'm talking about the bit before the sort.

e.g.

IF you want products that are red, and below 100 pounds:

Click Red, Click 100 pounds - URL then = www.domain.com/product/colour/red/price/sub100

then I use the htaccess to assign $color="red" and price="sub100"; and place these into my queries.

My problem is that you need a specific order in the .htaccess, so if they click in the reverse order (price, then color) i'll need a rule for that too
 
I would set it up, so that

www.domain.com/product/gender/mens/color/red

goes to something like

search.php?query1=gender&type1=mens&query2=color&type2=red

...then all you'd need is a pretty simple htaccess to set the first pair of values to query1 and type1, and to repeat this for as many pairs as were in the URL.

Then you use your PHP to do the hard work, constructing the SQL query based on the input that's received, e.g.

Code:
if(isset($_REQUEST['query1'])) {
  switch ($_REQUEST['query1']) {
    case 'gender':
    $query1 = 'gender';[/QUOTE]

hmm I can kinda see what you are saying.  

So by having it rewrite to  query=$1 instead of gender=$1 it doesn't matter what the first input is?

as the PHP would just take whatever is query 1 and compare using switch case like you said and set the variables accordingly

I guess this means i'll have lines in my htaccess for:

query1/type1
query1/type1/query2/type2
query1/type1/query2/type2/query3/type3 and so on depending on the amount of filters i have?
 
Back
Top Bottom