shorten rewrite rule
11 posts
• Page 1 of 1
shorten rewrite rule
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
And if i add another filter type, then it will start getting really long...
product/phones/state-ky/price-501-1000/color-red
Thanks!
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!
- mydearcosmo
- Posts: 5
- Joined: 26 Dec 2012, 23:38
Re: shorten rewrite rule
I am also working currently on this rule and would like to know how exact it should be done.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: shorten rewrite rule
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:
seems like you're checking if your mapfile has "product/phones" in it
regards
Andrew
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
Re: shorten rewrite rule
HeliconAndrew wrote:seems like you're checking if your mapfile has "product/phones" in it
Yep, thats what its doing.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: shorten rewrite rule
Our suggestion would be to use a set of rules.
regards
Andrew
regards
Andrew
Re: shorten rewrite rule
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.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: shorten rewrite rule
Hello,
Well, first, I'd say the mapfile is redundant. And the rules should look like the following:
These are the 3 rules to process requests with three level of parameters.
Regards
Andrew
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
Re: shorten rewrite rule
That would be a lot worse, I need the mapfile, there are 94 different categories in it
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: shorten rewrite rule
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
You may also consider putting the whole URL in mapfile. It may contain thousands of URLs and have no performance issues.
Regards
Andrew
Re: shorten rewrite rule
Is there a way to repeat the bolded part of the rule?
RewriteRule ^(.*)/(price-.*|state-.*|color-.*)$
RewriteRule ^(.*)/(price-.*|state-.*|color-.*)$
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: shorten rewrite rule
You mean to make it a variable and use it asmany times in your regular expression as you want? I don't think so...
11 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 53 guests