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]
LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
Your pattern match includes data you do not need and which you do not want.
RewriteRule ^swopshop/category/.*([^/\.?]\d+)$ swopshop/search/?cat=$1 [L]

The alternative is to redirect it to a script

RewriteRule ^(/swopshop/category/.*)$ /swopshop/search/$1 [L]

The search script alias will have the PATH_INFO/Query_string set with the data

Alternatively why waste resources on the rewrite rule, define the Alias for /swopshop to be going to a script and you resolve both types of entries at the same time.  I.e. the same setup you currently have for /swopshop/search needs/could be defined instead for /swopshop

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
arnoldCommented:
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.
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Excellent, many thanks Neil
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.