0

We have built a search module for our eCommerce application & attempting to build SEO friendly pages.

The basic concept below works however when adding additional params to our search the rules no longer work correctly.

RewriteRule ^shop/([^/]*)/([^/]*)/([^/]*)/search/([^/]*)$ search.php?controller=$1&lang=$2&name=$3&search_keyword=$4 [L]

Example of search but needs to also work with categories selection when parameter exists. www.mysite.com/shop/lcd

Currently this is working but only supports 2 category sets as we have 2 rules and not working with the search, the problem is there could be as many as 20 category sets

RewriteRule ^shop/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ search.php?controller=$1&lang=$2&name=$3&categories=$4=$5 [L]
RewriteRule ^shop/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ search.php?controller=$1&lang=$2&name=$3&categories=$4=$5|$6=$7 [L]

www.mysite.com/shop/TV/Plasma+3D+Portable/ (TV is the main category with 3 subs)

www.mysite.com/shop/TV/Plasma+3D+Portable/Computers/Mac+PC+Laptops+Tablets/ (Computers is the main category with 4 subs combined with the above)

This needs to also work with additional param sets www.mysite.com/shop/TV/Plasma+3D+Portable/Computers/Mac+PC+Laptops+Tablets/manufacturers/brandA/brandB/brandC/

Please if someone can suggest a better way to write these rules to support all these additional parameter requests we would really appreciate your input.

user828941
  • 145
  • 1
  • 9
  • What should be the internal URL for `www.mysite.com/shop/TV/Plasma+3D+Portable/Computers/Mac+PC+Laptops+Tablets/manufacturers/brandA/brandB/brandC/` after rewrite? – anubhava Jan 29 '14 at 21:08
  • This is the example after rewrite, we are using the + as the separator for the php & will explode the values to parse the URL for example: /shop/search.php?controller=category&lang=en&name=electronics&categories=TV=Plasma+3D+Portable|Computers=Mac+PC+Laptops+Tablets&manufacturers=brandA+brandB+brandC&search_keyword=macbook – user828941 Jan 29 '14 at 22:04
  • This question appears to be off-topic because it is about SEO and mod_rewrite – John Conde Jan 30 '14 at 12:57

1 Answers1

0

This post helped us to solve our problem .htaccess: GET variables are lost in rewrite

The solution is very simple in our case the controller lang & name our separated from the search parameters then params=/$4 captures the rest the URL which we can now explode & parse via PHP

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^shop/([^/]*)/([^/]*)/([^/]*)$ /search.php?controller=$1&lang=$2&name=$3 [QSA,L]    
RewriteRule ^shop/([^/]*)/([^/]*)/([^/]*)/(.*)$ /search.php?controller=$1&lang=$2&name=$3&params=/$4 [QSA,L]
Community
  • 1
  • 1
user828941
  • 145
  • 1
  • 9