shorten rewrite rule

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 6
Joined: 26 Dec 2012, 07:20

shorten rewrite rule

26 Dec 2012, 07:37

On my site, people can narrow results in any order they'd like. Is there a way to condense the below code into 1 rule?

Example pages:
product/phones/state-ky/price-501-1000
product/phones/price-501-1000/state-ky

Code: Select all
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)/(price-.*|state-.*)$ /ad_cat.php?id=${mapfile:$1}&fct[]=$2 [L,QSA]

RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)/(price-.*|state-.*)/(price-.*|state-.*)$ /ad_cat.php?id=${mapfile:$1}&fct[]=$2&fct[]=$3 [L,QSA]

And if i add another filter type, then it will start getting really long...

product/phones/state-ky/price-501-1000/color-red

Code: Select all
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)/(price-.*|state-.*|color-.*)/(price-.*|state-.*|color-.*)/(price-.*|state-.*|color-.*)$ /ad_cat.php?id=${mapfile:$1}&fct[]=$2&fct[]=$3&fct[]=$4 [L,QSA]


Thanks!

User avatar
Posts: 5
Joined: 26 Dec 2012, 23:38

Re: shorten rewrite rule

27 Dec 2012, 00:40

I am also working currently on this rule and would like to know how exact it should be done.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: shorten rewrite rule

28 Dec 2012, 05:51

Well,

You won't get away with just one rule. It won't be as reliable as several simple rules.

Also, it's hard to tell what you do with a line:
Code: Select all
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND

seems like you're checking if your mapfile has "product/phones" in it

regards
Andrew

User avatar
Posts: 6
Joined: 26 Dec 2012, 07:20

Re: shorten rewrite rule

01 Jan 2013, 16:10

HeliconAndrew wrote:seems like you're checking if your mapfile has "product/phones" in it

Yep, thats what its doing.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: shorten rewrite rule

03 Jan 2013, 05:04

Our suggestion would be to use a set of rules.

regards
Andrew

User avatar
Posts: 6
Joined: 26 Dec 2012, 07:20

Re: shorten rewrite rule

03 Jan 2013, 11:21

HeliconAndrew wrote:Our suggestion would be to use a set of rules.

Do you have anything to help me get started? I don't know how to do the rules i did any different.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: shorten rewrite rule

04 Jan 2013, 05:28

Hello,

Well, first, I'd say the mapfile is redundant. And the rules should look like the following:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteRule ^product/phones/(price-.*|state-.*)$ /ad_cat.php?id=YOUR_ID_HERE&fct[]=$1 [L,QSA]

RewriteRule ^product/phones/(price-.*|state-.*)/(price-.*|state-.*)$ /ad_cat.php?id=YOUR_ID_HERE&fct[]=$1&fct[]=$2 [L,QSA]

RewriteRule ^product/phones/(price-.*|state-.*|color-.*)/(price-.*|state-.*|color-.*)/(price-.*|state-.*|color-.*)$ /ad_cat.php?id=YOUR_ID_HERE&fct[]=$1&fct[]=$2&fct[]=$3 [L,QSA]


These are the 3 rules to process requests with three level of parameters.

Regards
Andrew

User avatar
Posts: 6
Joined: 26 Dec 2012, 07:20

Re: shorten rewrite rule

04 Jan 2013, 19:41

That would be a lot worse, I need the mapfile, there are 94 different categories in it

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: shorten rewrite rule

04 Jan 2013, 20:18

I see... I guess you need the same stuff bu with the mapfile check.
You may also consider putting the whole URL in mapfile. It may contain thousands of URLs and have no performance issues.

Regards
Andrew

User avatar
Posts: 6
Joined: 26 Dec 2012, 07:20

Re: shorten rewrite rule

05 Jan 2013, 02:41

Is there a way to repeat the bolded part of the rule?

RewriteRule ^(.*)/(price-.*|state-.*|color-.*)$

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: shorten rewrite rule

07 Jan 2013, 16:40

You mean to make it a variable and use it asmany times in your regular expression as you want? I don't think so...

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 53 guests