/    Sign up×
Community /Pin to ProfileBookmark

help with advanced mod_rewrite rule

I have a search engine for products on a site which I would like to give search engine friendly URLs using mod_rewrite. I use mod_rewrite frequently for simple tasks, but this one is a bit more akward.

I want this URL:
/search/cookies/betty-crocker/page1/name/

to be rewritten as
/search/products.php?q=cookies&brand=betty+crocker&page=1&order_by=name

I want to replace spaces with dashes for the ‘q’ and ‘brand’ variables in the nice URL
I want to prefix the ‘page’ variable with ‘page’ in the nice URL.
I want the ‘brand’ URL to be optional… that is, if it’s missing, then I do the same rules but without it all together so that the defaults can take over. In fact, any of them can be missing. This is the part that seems really hard to me.

Suggestions?

to post a comment
SEO

0Be the first to comment 😎

×

Success!

Help @MicahCarrick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...