Man Perfect
Man Perfect

Reputation: 73

What's wrong my url rewrite regex

I use url rewrite. I add some rule like that:

<add name="Homes" virtualUrl="^/(.*).html" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/Default.aspx?vsm=$1" ignoreCase="true" />
  <add name="HomeNew" virtualUrl="^/(.*)/(.*)/" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/Default.aspx?vsm=$1&amp;idcnew=$2" ignoreCase="true" />
  <add name="HomeNewPage" virtualUrl="^/(.*)/(.*)/page-([0-9-]*).htm" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/Default.aspx?vsm=$1&amp;idcnew=$2&amp;page=$3" ignoreCase="true" />
  <add name="HomeNewNew" virtualUrl="^/(.*)/(.*)/(.*)-([0-9-]*).htm" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/Default.aspx?vsm=$1&amp;idcnew=$2&amp;idnew=$4" ignoreCase="true" />

I have to use all of them. In HomeNewPage rule, I use to get catalog new page. In HomeNewNew rule, I use to get content new with $3 is url name of new. But when go to this link: "/News/Alert/page-2" my request is "vsm=News&idcnew=Alertpage-2" I want my request is "vsm=News&idcnew=Alert&page=2" Please help me! What's wrong? And how to fix it?

Upvotes: 0

Views: 84

Answers (2)

Tanul
Tanul

Reputation: 354

According to me your Regex expression:

/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/page-([0-9-]*)\.htm

will work. But this expression

/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/"

wont work as it does consist of arguement for third tag(page-2). But this will work till /News/Alert. Please check your code or try to debug it according to me there is some hardcoding done. Due to which you're getting error.

I'll give you a very easy way to detect your expressions. After this you'll be able to validate your expressions appropriately.

Go to this link : http://www.rexfiddle.net/

And insert your expression and in second window insert the url you want. After this you'll get captures in the end linke capture 1, capture 2, capture 3. These will be come out to be your arguements($1, $2......). See the screenshot below:

Result_1st_expresssion

Upvotes: 0

Tanul
Tanul

Reputation: 354

If the url is like

  • "/Default/News/Alert/page-2.html"

    Regex:-  /(.*)/(.*)/(.*)/page-(.*).html
    
  • "/Default/News/Alert/page-2"

    Regex:- /(.*)/(.*)/(.*)/page-(.*)

    and you can make the new url as /Default.aspx?vsm=$2&idcnew=$3&page=$4

Basically each (.*) specify the argument like

  • Default is $1
  • News is $2
  • Alert is $3
  • But we've hardcoded the page- so its not an argument. So, (.*) after page- comes out to be argument $4

If we take your second expression ^/(.*)/(.*)/. In this case it may creates the problem with url like News/Alert/page-2 because it doesn't "/" in the end. Same is the reason with .html. As you've not provided the url so I'm not sure about ^. But this will come only if your url will fulfill the regex from first character, however, it wont leads to any problem. You can specify or remove it.

Upvotes: 1

Related Questions