I have the following URL rewriting rule (IIS 7.5 URL Rewrite module/ASP.NET) in place:
www.domain.com/page.html?id=1
www.domain.com/page/1
I want to add an optional tracking parameter, p=1, to the rewritten URL. Should I use a ? or an &?
www.domain.com/page/1?p=1
or
www.domain.com/page/1&p=1
Both seem to work, I'd just like to know the "correct" way to do this to avoid any compliance/compatibility issues.
Related
i am trying to rewrite any URL that match this pattern:
~/Ahmed
~/Name
to this:
~/User/Ahmed/Ahmed.aspx
~/User/Name/Name.aspx
and i can write them individually but what i am trying to do is detect any URL that look like "~/User/Ahmed/Ahmed" and auto rewrite them to this "Ahmed"
thanks
Hopefully you're using the UrlRewritingNet library, not UrlRewriter? The former is suggested over the latter.
However, in either you can use a regex:
"~/User/([^/\\]+)/\1.aspx" -> "~/$1" //For ".aspx" in the URL
"~/([A-Za-z]+)" to "~/User/$1/$1.aspx" //For /Name in the URL.
Note the ([^/\]+) means any set of characters without slashes,
and "\1" is a backreference to the previous capture, that ensures the name is an exact duplicate. Note that you should enable "ignore case" if you want to support "/User/ahmed/Ahmed.aspx" and not just "/User/Ahmed/Ahmed.aspx".
I am creating a Friendly URL Patterns in IIS Rewrite
my normal URL would look like this
http://localhost/orgprofile/financial.aspx?name=Test
and initially I picked from the options available in IIS
the friendly URL with
http://localhost/orgprofile/financial/test
With Pattern
^orgprofile/financial/([^/]+)/?$
Now I only want to change the friendly URL to
http://localhost/test/financial
So yes the querystring first then append financial
I can get this friendly URL to work
http://localhost/financial/test
^financial/([^/]+)/?$
But cant get this to work
http://localhost/test/financial
i.e something like
([^/]+)/?$/^financial
$ means the end of the query string - you need to leave that at the end.
Try:
^([^/]+)/financial/?$
I need to be able to get the URL as I see it in the browser i.e The rewritten one. For instance:
If my Url was www.myurl.com/Test.html and I then used Request.Url.AbsoluteUri, the URL returned would be: www.myurl.com/Default.aspx?Action=Test
I need to be able to get back the exact rewritten URL.
Does anyone know how I can achieve this?
From Tchami:
Have you tried Request.RawUrl? I think that gives you the unmapped URL.
Will mark this as the answer when I am allowed.
You could rewrite the URL so, that it includes the original URL as a querystring parameter.
For example: url="(.*)" to="http://newurl.com?original=$1".
(Note you'll still have to adjust the regex to work with URLs that contain a querystring.)
Is it possible, using regex, to parse the query string and build a nice URL that can be translated back to the ugly URL for use on a legacy application? For example, let's say we are not certain what query string parameters are going to be part of a URL. Here is an example:
http://www.domain.com/thePage.aspx?Param1=1&Param2=23&Param7=22
We want to rewrite the URL as
http://www.domain.com/Param1/1/Param2/23/Param7/22
At the same time we need the filter to allow the application to see it as the old URL to be processed correctly. Again, we don't know what combination of parameters may be used.
Can this be done only using the filter?
As official forums said, you can use RewriteCompatibility2 on in Helicon 3.0, so you can use a LP directive (looping with the replace).
I use this ReGex to parse QueryString (it makes two groups: name with all parameter names, and value with all parameter values)
[\?&](?<name>[^&=]+)=(?<value>[^&=]+)
Based on mentioned forum topic, I think you should try something like this:
//for replacing '='
RewriteRule ^[\?&]([^&=]+)=([^&=]+)$ $1/$2 [LP,R=301,L]
//for replacing '&'
RewriteRule ^\?([^&]+)&([^&]+)$ $1/$2 [LP,R=301,L]
I am using the Intelligencia URL rewriter in my asp.net web application.
I use the web.config mappings
I'm trying to map the following url:
www.mydomain.com/product-deals/manufacturer-model_PRODUCTId.aspx
To:
www.mydomain.com/ProductInfo.aspx?productID=xxx
obviously in the above example, xxx is replaced from the "productId" from the "friendly" url.
In my web.config, I've got so far:
<rewrite url="~/contract-deals/([\w-_]+)/_(.+).aspx" to="~/ProductInfo.aspx?productId=$1"/>
This isn't working however.
I need the correct regex to use for my requirements (regex really isn't my strong point!!)
One problem is that you have product-deals in your sample and contract-deals in the regex.
Next, your regex has an extra slash, and you don't escape the dot (though it can match a dot anyway). Also, $1 refers to the first capturing group, which in your case is "manufacturer-model".
This regex should get you what you want:
product-deals/[\w_-]+_(.+)\.aspx