Reputation: 625
Looking for some help with setting up al UrlRewrite for the same page with different querystring parameters.
Below are the two urls that I am looking to rewrite
stockists.aspx?product=1&fragrance=2
stockists.aspx?store=1
I setup the url rewrite for stockists.aspx?product=1&fragrance=2 (in config/UrlRewriting.config) first and tested successfully.
<add name="Stockists"
virtualUrl="^~/stockists/(.*)/(.*).aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/stockists.aspx?product=$1&fragrance=$2"
ignoreCase="true" />
I then setup the url rewrite for stockists.aspx?store=1 (in config/UrlRewriting.config) and now neither url rewrite works.
<add name="Stores"
virtualUrl="^~/stockists/(.*).aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/stockists.aspx?store=$1"
ignoreCase="true" />
Any suggestions on how the above can be achieved?
Upvotes: 0
Views: 2161
Reputation: 2392
As it is now, the Stores rewrite would also match the url format that the Stockists rewrite is matching. (.*)
matches any number of any characters. To fix this, each (.*)
should be changed to ([^/]+)
. That will match any character except a forward slash and also makes sure that there is at least one character.
<add name="Stockists"
virtualUrl="^~/stockists/([^/]+)/([^/]+).aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/stockists.aspx?product=$1&fragrance=$2"
ignoreCase="true" />
<add name="Stores"
virtualUrl="^~/stockists/([^/]+).aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/stockists.aspx?store=$1"
ignoreCase="true" />
Now, this might not completely solve the problem, but it should allow the Stockists rewrite to work again. I suspect there is something else wrong with the Stores rewrite, but the Stockists rewrite stopped working because the url pattern was matched by the Stores rewrite.
Upvotes: 1