Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 2.x
 Helicon Tech : ISAPI_Rewrite 2.x
Subject Topic: Writing Generic Rules Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
bfigueira
Newbie
Newbie


Joined: 02 September 2010
Online Status: Offline
Posts: 5
Posted: 02 September 2010 at 4:29am | IP Logged Quote bfigueira

I have the following set of rules:

RewriteRule ^policies/(.+)/(.+)/(.+)/(.+)$ /ContentPage/Policies.aspx?CategoryName=ABC|$1|$2|$3|$4 [NC,L,QSA]

RewriteRule ^policies/(.+)/(.+)/(.+)$ /ContentPage/Policies.aspx?CategoryName=ABC|$1|$2|$3 [NC,L,QSA]

RewriteRule ^policies/(.+)/(.+)$ /ContentPage/Policies.aspx?CategoryName=ABC|$1|$2 [NC,L,QSA]

RewriteRule ^policies/(.+)$ /ContentPage/Policies.aspx?CategoryName=ABC|$1 [NC,L,QSA]

RewriteRule ^policies$ /ContentPage/Policies.aspx?CategoryName=ABC [NC,L,QSA]

Is there a way I can avoid repeating the rule by making a generic rule, considering that if I have about 5 to 6 categories then i would have to repeat it that many times.
Please let me know.

Thanks in advance.

Back to Top View bfigueira's Profile Search for other posts by bfigueira
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10489
Posted: 02 September 2010 at 4:35am | IP Logged Quote Anton

Yes, please try to have it like this (for 4 cats):

RewriteRule ^policies(?:/(.+))?(?:/(.+))?(?:/(.+))?(?:/(.+))?$ /ContentPage/Policies.aspx?CategoryName=ABC(?1|$1)(?2|$2)(?3|$3)(?4|$4) [NC,L]

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
bfigueira
Newbie
Newbie


Joined: 02 September 2010
Online Status: Offline
Posts: 5
Posted: 02 September 2010 at 8:17am | IP Logged Quote bfigueira

Thanks a lot Anton it works fine.

However when i modified it to

RewriteRule ^(?:/(.+))?(?:/(.+))?(?:/(.+))?(?:/(.+))?$ /ContentPage/StoryListing.aspx?CategoryName=(?1|$1)(?2|$2)(?3|$3)(?4|$4) [NC,L,QSA]

it did not work for the below set:

RewriteRule ^(.+)/(.+)/(.+)/(.+)$  /ContentPage/List.aspx?CategoryName=$1|$2|$3|$4 [NC,L,QSA]

RewriteRule ^(.+)/(.+)/(.+)$  /ContentPage/List.aspx?CategoryName=$1|$2|$3 [NC,L,QSA]

RewriteRule ^(.+)/(.+)$  /ContentPage/List.aspx?CategoryName=$1|$2 [NC,L,QSA]

RewriteRule ^(.+)$  /ContentPage/List.aspx?CategoryName=$1 [NC,L,QSA]

Can you please tell me what i have done incorrectly?

I interpreted the last question mark as optional (?:/(.+))?. Can you please tell me what is ?:/.

Thanks

Back to Top View bfigueira's Profile Search for other posts by bfigueira
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10489
Posted: 02 September 2010 at 8:32am | IP Logged Quote Anton

"it did not work for the below set:"
- for the above new set of rules I suggest the following generic rule:

RewriteRule ^(?!policies/.*)(.+)(?:/(.+))?(?:/(.+))?(?:/(.+))?$ /ContentPage/List.aspx?CategoryName=$1(?2|$2)(?3|$3)(?4|$4) [NC,L]

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
bfigueira
Newbie
Newbie


Joined: 02 September 2010
Online Status: Offline
Posts: 5
Posted: 24 September 2010 at 7:24am | IP Logged Quote bfigueira

Thanks for the above Anton, but there is a slight problem. It works fine if the URL is in the format

http://localhost:2497/ContentPage/List.aspx?CategoryName=Sports

But does not work if there is a sub category such as

http://localhost:2497/ContentPage/List.aspx?CategoryName=Sports|Football

OR

http://localhost:2497/ContentPage/List.aspx?CategoryName=Sports|Basketball

Kindly provide your comments.

Thanks.

Back to Top View bfigueira's Profile Search for other posts by bfigueira
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10489
Posted: 27 September 2010 at 8:46am | IP Logged Quote Anton

Sorry it not clear enough...
Could you please show the examples of working and non-working requests and what results they should produce.

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
bfigueira
Newbie
Newbie


Joined: 02 September 2010
Online Status: Offline
Posts: 5
Posted: 29 September 2010 at 1:39am | IP Logged Quote bfigueira

Ok. Here is the first issue:

Existing rules: The rule is repeated based on the number of parameters. Need to make it generic if possible.

RewriteRule ^tags/(.+)/?$ /ContentPage/Search.aspx?CatName=&Tags=$1&searchtype=NormalSearch [NC,L,QSA]

RewriteRule ^(.+)/(.+)/(.+)/(.+)/tags/(.+)/?$ /ContentPage/Search.aspx?CatName=$1|$2|$3|$4&Tags=$5&searchedCategories=&refineCategories=&searchtype=NormalSearch [NC,L,QSA]

RewriteRule ^(.+)/(.+)/(.+)/tags/(.+)/?$ /ContentPage/Search.aspx?CatName=$1|$2|$3&Tags=$4&searchedCategories=&refineCategories=&searchtype=NormalSearch [NC,L,QSA]

RewriteRule ^(.+)/(.+)/tags/(.+)/?$ /ContentPage/Search.aspx?CatName=$1|$2&Tags=$3&searchedCategories=&refineCategories=&searchtype=NormalSearch [NC,L,QSA]

RewriteRule ^(.+)/tags/(.+)/?$ /ContentPage/Search.aspx?CatName=$1&Tags=$2&searchedCategories=&refineCategories=&searchtype=NormalSearch [NC,L,QSA]

2nd issue:

Existing rules: The rule is repeated based on the number of parameters. Need to make it generic.

RewriteCond %{QUERY_STRING} &?pgtype=p&? [NC]
RewriteRule ^(.+)/(.+)/(.+)/(.+)/(.+)/s/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})/(a|e)/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})$ /ContentPage/AssetDetail.aspx?CatName=$1|$2|$3|$4&GUID=$6&aGUID=$8 [NC,L,QSA]

RewriteCond %{QUERY_STRING} &?pgtype=p&? [NC]
RewriteRule ^(.+)/(.+)/(.+)/(.+)/s/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})/(a|e)/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})$ /ContentPage/AssetDetail.aspx?CatName=$1|$2|$3&GUID=$5&aGUID=$7 [NC,L,QSA]

RewriteCond %{QUERY_STRING} &?pgtype=p&? [NC]
RewriteRule ^(.+)/(.+)/(.+)/s/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})/(a|e)/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})$ /ContentPage/AssetDetail.aspx?CatName=$1|$2&GUID=$4&aGUID=$6 [NC,L,QSA]

RewriteCond %{QUERY_STRING} &?pgtype=p&? [NC]
RewriteRule ^(.+)/(.+)/s/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})/(a|e)/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})$ /ContentPage/AssetDetail.aspx?CatName=$1&GUID=$3&aGUID=$5 [NC,L,QSA]

RewriteCond %{QUERY_STRING} &?pgtype=p&? [NC]
RewriteRule ^(.+)/s/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})/(a|e)/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})$ /ContentPage/AssetDetail.aspx?CatName=HOME&GUID=$2&aGUID=$4 [NC,L,QSA]

RewriteCond %{QUERY_STRING} &?pgtype=p&? [NC]
RewriteRule ^s/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})/(a|e)/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})$ /ContentPage/AssetDetail.aspx?CatName=HOME&GUID=$1&aGUID=$3 [NC,L,QSA]

Back to Top View bfigueira's Profile Search for other posts by bfigueira
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10489
Posted: 29 September 2010 at 7:26am | IP Logged Quote Anton

1. Please give this a try:
RewriteRule ^(?:([^/]+)/(?:([^/]+)/(?:([^/]+)/(?:([^/]+)/)?)?)?)?tags/(.+)/?$ /ContentPage/Search.aspx?CatName=(?1$1)(?2|$2)(?3|$3)(?
4|$4)&Tags=$5&searchedCategories=&refineCategories=&searchtype=NormalSearch [NC]

2. and this:
RewriteRule ^(?:([^/]+)/(?:([^/]+)/(?:([^/]+)/(?:([^/]+)/(?:([^/]+)/)?)?)?)?)?s/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-
[a-zA-Z0-9]{12})/(?:a|e)/([a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})$ /ContentPage/AssetDetail.aspx?CatName=
(?5$1|$2|$3|$4:(?4$1|$2|$3:(?3$1|$2:(?2$1))))&GUID=$6&aGUID=$7 [NC]

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
bfigueira
Newbie
Newbie


Joined: 02 September 2010
Online Status: Offline
Posts: 5
Posted: 04 October 2010 at 11:38pm | IP Logged Quote bfigueira

Thanks a lot Anton.
Back to Top View bfigueira's Profile Search for other posts by bfigueira
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum