I have a question concerning urlrewiter. I want to rewrite the following url like this:
<rewrite url="~/sportswear/browse-by-category/(\d+)/(.+)/(\d+)" to="~/Browse.aspx?cid=9&type=category&mid=$1&p=$2" />
This does work but my get variable p cannot be read. However when i write 'shoes' which is the categoryname instead of (.+) it works perfectly. Does anyone know what seems to be the problem?
Thanks for your time.
Kind regards,
Mark
Actually, you should start learning to make your groups non capture:
<rewrite url="~/sportswear/browse-by-category/(\d+)/(?:.+)/(\d+)" to="~/Browse.aspx?cid=9&type=category&mid=$1&p=$2" />
Basically, just use (?:) instead of () if you don't want to capture it.
Additionally, there was no need to group that .+, no?
<rewrite url="~/sportswear/browse-by-category/(\d+)/.+/(\d+)" to="~/Browse.aspx?cid=9&type=category&mid=$1&p=$2" />
Oooow sorry guys, i figured it out already, i had to replace $2 with $3 since that was the regex array number. Thanks anyways! :)
Related
I have searched on google and stackoverflow but didnt find a good answer. I also tryed it by myself, but iam no regex guru.
My goal is to replace all relative urls in a html style tag with the absolute version.
e.g.
style="url(/test.png)" with style="url(http://mysite.com/test.png)"
style="url("/test.png")" with style="url("http://mysite.com/test.png")"
style="url('/test.png')" with style="url('http://mysite.com/test.png')"
style="url(../test.png)" with style="url(http://mysite.com/test.png)"
style="url("../test.png")" with style="url('http://mysite.com/test.png')"
style="url('../test.png')" with style="url('http://mysite.com/test.png')"
and so on.
Here what i tryed with my poor regex "skils"
url\((?<Url>[^\)]*)\)
gives me the url in the "url" function.
thanks in advance!
Well, you can try the regex:
style="url\((['"])?(?:\.\.)?(?<url>[^'"]+)\1?\)"
And replace with:
style="url($1http://mysite.com$2$1)"
regex101 demo
(['"])? will capture quotes if they are present and use them again at \1?
([^'"]+) will capture the url itself.
In my appication i used to URL Rewrite using Intelligencia.
My URL Pattern is
<rewrite url="~/([A-Za-z0-9-_ ]+)$" to="~/xxxxxx.aspx?id=$1"/>
Now i want if the URL doesn't contain iphonestatelist,iphonepropertytype then only it should redirect.
I have used this below code but it does not working.
<rewrite url="~/(^((?!\b(iphonestatelist|iphonepropertytype)\b).)*[A-Za-z0-9-_ ]+)$" to="~/xxxxxx.aspx?id=$1"/>
Eg:
The below URL dont want to Rewrite
www.xxxx.com/abc/sef/iphonestatelist
The right URL to Rewrite
www.xxxx.com/FX1234
Try
<rewrite
url="^(?!.*?\b(?:iphonestatelist|iphonepropertytype)\b)~/([A-Za-z0-9-_ ]+)$"
to="~/xxxxxx.aspx?id=$1"
/>
Generally: To check if a string contains (or does not contain) a certain sub-string, use a look-ahead (or negative look-ahead, respectively) like this:
^(?=.*?pattern-reqired)pattern-you-look-for
^(?!.*?pattern-disallowed)pattern-you-look-for
These patterns can also be chained
^(?!.*?not-this)(?!.*?not-that)pattern-you-look-for
Try
<rewrite
url="^(?!.*?\b(?:iphonestatelist|iphonepropertytype)\b)~/([A-Za-z0-9-_ ]+)$"
to="~/xxxxxx.aspx?id=$1"
/>
Generally: To check if a string contains (or does not contain) a certain sub-string, use a look-ahead (or negative look-ahead, respectively) like this:
`^(?=.*?pattern-reqired)pattern-you-look-for
^(?!.*?pattern-disallowed)pattern-you-look-for
These patterns can also be chained
^(?!.?not-this)(?!.?not-that)pattern-you-look-for`
I have a RegEx problem. Consider the following URL:
http://ab.cdefgh.com/aa-BB/index.aspx
I need a regular expression that looks at "aa-BB" and, if it doesn't
match a number of specific values, say:
rr-GG
vv-VV
yy-YY
zz-ZZ
then the URL should redirect to some place. For example:
http://ab.cdefgh.com/notfound.aspx
In web.config I have urlrewrite rules. I need to know what
the regex would be between the tags.
<urlrewrites>
<rule>
<url>?</url>
<rewrite>http://ab.cdefgh.com/notfound.aspx</rewrite>
</rule>
</urlrewrites>
Assuming you don't care about the potential for the replacement pattern to be in the domain name or some other level of the directory structure, this should select on the pattern you're interested in:
http:\/\/ab\.cdefgh\.com\/(?:aa\-BB|rr\-GG|vv\-VV|yy\-YY|zz\-ZZ)\/index\.aspx
where the aa-BB, etc. patterns are simply "or"ed together using the | operator.
To further break this apart, all of the /, ., and - characters need to be escaped with a \ to prevent the regex from interpreting them as syntax. The (?: notation means to group the things being "or"ed without storing it in a backreference variable (this makes it more efficient if you don't care about retaining the value selected).
Here is a link to a demonstration (maybe this can help you play around with the regex here to get to exactly which character combinations you want)
http://rubular.com/r/UfB65UyYrj
Will this help?
^([a-z])\1-([A-Z])\2.*
It matches:
uu-FF/
aa-BB/
bb-CC/index
But not
aaBB
asdf
ba-BB
aA-BB
(Edit based on comment)
Just pipe delimit your desired urls inside of () and escaping special chars.
Eg.
^(xx-YY|yy-ZZ|aa-BB|goodStuff)/.*
But, I think you might actually want the following which matches anything other than the urls that you specify, so that all else goes to notfound.aspx:
^[^(xx-YY|yy-ZZ|aa-BB|goodStuff)]/.*
Assuming you want anything but xx-XX, yy-YY and zz-ZZ to redirect:
[^(xx\-XX)|(yy\-YY)|(zz\-ZZ)]
Sample text =
legacycard.ashx?save=false&iNo=3&No=555
Sample pattern =
^legacycard.ashx(.*)No=(\d+)
Want to grab group #2 value of "555" (the value of "No=" in the sample text)
In Expresso, this works, but in ASP.NET UrlRewrite, it is not catching.
Am I missing something?
Thanks!
I would do something along these lines:
^legacycard.ashx\?(?:.+&)*No=(\d+)
The \? will escape the question mark that normally separates the URL and the parameters, then you make sure that it will capture every parameter key/value pair (anything that ends on &) before the parameter you actually care about. Using ?: lets you specify that the set of brackets is non capturing (I'm assuming you won't need any of the data, has the potential to slightly speeds up your regex) and leaves you just 555 captured. The added benefit of this approach is that it'll work regardless of parameter order.
Just use this regex:
^legacycard\.ashx\?save=(false|true)&iNo=(?<ino>\d+)&No=(?<no>\d+)
Then Regex Replace with
${no}
Looks fine to me, your regex should match the entire string
legacycard.ashx?save=false&iNo=3&No=555
not sure why you have groups, but groups should also return
?save=false&iNo=3&
and
555
For good measure you should know that the . in legacycard.ashx is also interpreted by regex and you would normally escape it, in this case it dosen't matter because a single dot matches everything, also a dot. :)
Try this
^legacycard.ashx(\?No=|.*?&No=)(\d+)
this should work.
Hi all I get the Server Tag Not Well Formed error on the following line of code.
<a class="button"><span><input id="btnEmbedCodes" type="button"
value="Click for Embed Codes" onclick='javascript:window.open("%=ExternalLink%>","ExternalFeeds","height=575,width=675,
scrollbars=yes,overflow-x:hidden")'; Style="width:165px" /></span></a>
Please help me out. Thanks
window.open("%=ExternalLink%>"
In this starting "<" is missing. Seems like that is the problem.
It looks like you missed a < in the first argument of your javascript function
You are missing the opening bracket before ExternalLink
You have missed less than sign (<) before ExternalLink and also surround it with single quotes rather than double quotes.
Thanks.