Repetition.. repetition = bad?

Discuss practical ways rearrange URLs using mod_rewrite.

Repetition.. repetition = bad?

Postby Vincjenzo » Tue Oct 20, 2009 11:34 pm

Hi everyone. I'm having a bit of trouble in the complex world of mod_rewrite. I'm still a newbie when it comes to this.

The problem is I'm repeating my rules too often I think. Repeating code is never a good thing right, so I hope you can help me.

These are my current rewrite rules:

Code: Select all
<IfModule mod_rewrite.c>
# Turn on the furnace.
    RewriteEngine on

# Search for a brand
    RewriteRule supplier/([a-z_0-9]+) index.php?var[]=search&b=$1 [NC]

# Search for a product (numbers only!)
    RewriteRule product/([0-9]+) index.php?var[]=product&var[]=$1 [NC]

# 1-1-1/(abc-12)_(abc-12)_(abc-12)
    RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)/([a-z0-9-]+)_([a-z0-9-]+)_([a-z0-9-]+) index.php?var[]=search&tree[]=$1&tree[]=$2&tree[]=$3&c=$4&s[]=$5&s[]=$6 [NC]

# 1-1/(abc-12)_(abc-12)_(abc-12)
    RewriteRule ^([0-9]+)-([0-9]+)/([a-z0-9]+)_([a-z0-9-]+)_([a-z0-9-]+) index.php?var[]=search&tree[]=$1&tree[]=$2&c=$3&s[]=$4&s[]=$5 [NC]

# 1-1-1/(a_bc-12)
    RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)/([a-z_0-9-]+) index.php?var[]=search&tree[]=$1&tree[]=$2&tree[]=$3&&c=$4 [NC]

# 1-1/(a_bc-12)
    RewriteRule ^([0-9]+)-([0-9]+)/([a-z_0-9-]+) index.php?var[]=search&tree[]=$1&tree[]=$2&c=$3 [NC]

# 1/(a_bc-12)
    RewriteRule ^([0-9]+)/([a-z_0-9-]+) index.php?var[]=search&tree[]=$1&c=$2 [NC]

</IfModule>


My links look like:
http://example.com/83/componenten.html <-- mainmenu
http://example.com/83-57/ram.html <-- submenu
http://example.com/83-57-61/ram_technol ... sdram.html <-- 3rd level (and so on)

My links for showing a product look like:
http://example.com/product/8189/ <-- product Id

Or, to keep the menu links 'open' when someone clicks a link in one of the overviews:
http://example.com/83-57-61/product/8189/

Or request all product by a supplier:
http://example.com/supplier/kingston.html

Basicly the menu can have an 'unlimited' amount of levels. This would cause me to have many of the same rewrite rules and might lead to an unmaintainable mess.

I'd appreciate any suggestions,
Vinc
Vincjenzo
 
Posts: 1
Joined: Tue Oct 20, 2009 11:17 pm

Postby richardk » Wed Oct 21, 2009 10:07 am

Pass them together to PHP and explode() them.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron