In my project, my /PropertDetail.aspx can get 2 querystrings.
1st one for the PropertyId /PropertDetail.aspx?PropertyId=5
2nd one for the Language /PropertDetail.aspx?PropertyId=5&Language=2
EDIT: and this page can get one of them or can get both of them, so my rewriter rule needs to handle both of them
So, i have set these rules to web.config
<rewriter>
<rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?)$" to="$1" processing="stop" />
<rewrite url="^/(.+)-(.+).aspx$" to="/PropertyDetail.aspx?PropertyId=$2" processing="stop"/>
<!--http://localhost:1562/Harika-Gayrimenkul-5.aspx-->
<rewrite url="^/(.+)-(.+)-(.+).aspx$" to="/PropertyDetail.aspx?PropertyId=$2&Language=$3" processing="stop"/>
<!--http://localhost:1562/Great-Property-5-2.aspx-->
</rewriter>
It is all OK if there is no Language querystring, but when there is a language querystring it gets the 3rd expression as the PropertyId instead of Language
How can i define these two rules for the same page ?
Thanks
Combined answer:
<rewriter>
<rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?)$" to="$1" processing="stop"/>
<rewrite url="^.+?([\d]+?)-([\d]+?)\.aspx$" to="/PropertyDetail.aspx?PropertyId=$1&Language=$2" processing="stop"/>
<rewrite url="^.+?-([\d]+?)\.aspx$" to="/PropertyDetail.aspx?PropertyId=$1" processing="stop"/>
</rewriter>
That's working well now for many combinations:
/This-is-a-really-long-property-title-555-12
returns PropertyId=555 and Language=12.
/This-is-another-really-long-property-title-666
returns PropertyId=666.
Make the second parameter (the language value) optional in the match by adding a question mark:
Edit: this is a corrected version, made after I realized that I misunderstood the question a bit.
<rewriter>
<rewrite url="\.(?:gif|png|jpg|ico|pdf|css|js)(?:\?.*)?$" to="$0" processing="stop"/>
<rewrite url="(\d+)(?:-?(\d+)?)\.aspx$" to="/PropertyDetail.aspx?PropertyId=$1&Language=$2" processing="stop"/>
</rewriter>
This is a cleaned-up and streamlined version of what the OP has working. It will produce output in the form of
/PropertyDetail.aspx?PropertyId=12345&Language=1 (when language is present) /PropertyDetail.aspx?PropertyId=12345&Language= (when it isn't)
Note
Original version of the answer:
<rewriter>
<rewrite url="^/(.+?)-(.+?)-?(.+?)?\.aspx$" to="/PropertyDetail.aspx?PropertyId=$2&#038;Language=$3" processing="stop"/>
</rewriter>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With