Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Apache RewriteRule query

Hi

I'm writing a shop and have my URL's a bit more human friendly like this: http://www.mysite.co.uk/swopshop/category/kitchen/126 but the only thing I'm really interested in is the final number (e.g. the category number 126 in the database)

How can I use re-write to use URL's like this (they could be any length and number of paths /) but then simply ignore everything but the last number and go to the required URL

For example:
http://www.mysite.co.uk/swopshop/category/kitchen/126 would simply go to http://www.mysite.co.uk/swopshop/search/?cat=126


and

http://www.mysite.co.uk/swopshop/category/clothing/childrens/boys/trousers/456 would simply go to http://www.mysite.co.uk/swopshop/search/?cat=456


I'm guessing its something like this but no real idea :(
RewriteRule ^swopshop/category/([^/\.]+)/?$ swopshop/search/?cat=$1 [L]
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Neil Thompson

ASKER

Thanks Arnold

I also have a lot of other "parts" within the swopshop, these are for example swopshop/ask/ swopshop/edit/ swopshop/add etc so I was just trying to tie in the category search to the main search to only then have 1 template to create to show the products, whether it be based on category, user, wildcard search etc.

With that in mind would your last paragraph work for me? would you see the script then deciding where to go next?

Neil
Tie the /swopshop/category  as though it is /swopshop/search
Once the request is passed to the script, it can do whatever you need to it and refirect to the search path or actually provide the response.
Excellent, many thanks Neil