This forum has been moved here:
Helicon Tech Community Forum

  Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 2.x (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 2.x
Subject Topic: Writing Generic Rules
Author
Message |
bfigueira
Newbie


Joined: 02 September 2010
Posts: 5
Posted: 02 September 2010 at 4:29am

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
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 02 September 2010 at 4:35am

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
 
bfigueira
Newbie


Joined: 02 September 2010
Posts: 5
Posted: 02 September 2010 at 8:17am

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
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 02 September 2010 at 8:32am

"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
 
bfigueira
Newbie


Joined: 02 September 2010
Posts: 5
Posted: 24 September 2010 at 7:24am

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
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 27 September 2010 at 8:46am

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
 
bfigueira
Newbie


Joined: 02 September 2010
Posts: 5
Posted: 29 September 2010 at 1:39am

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
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 29 September 2010 at 7:26am

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
 
bfigueira
Newbie


Joined: 02 September 2010
Posts: 5
Posted: 04 October 2010 at 11:38pm

Thanks a lot Anton.
Back to Top
 

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

Printable version Printable version
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