URL ReWriter for .NET - asp.net

I am using this, but I have some hard to solve problems.
This is part of my code:
<rewrite url="/Dictionary/(.+)/(.+)" to="~/Dictionary.aspx?page=$2&&word=$1"/>
<rewrite url="/Dictionary" to="~/Dictionary.aspx"/>
When I type links like mywebsite.com/Dictionary/cat/4 the site loads only mywebsite.com/Dictionary.

Just a guess. Your second condition matches everything starting with /Dictionary.
You probably want this
/Dictionary/?$

Just a suggestion but you can also try out IIS Url Rewrite 2 instead.

URL Rewrite 2 is a good option like XII said, comes with an user interface.
Regarding the regex, it would be more efficient for the regex engine to avoid backtracking; use the following expression instead:
"/Dictionary/([^/]+)/([^/]+)"

Related

Regex for fixing URL patterns

I have the following url structure:
http://www.xyxyxyxyx.com/ShowProduct.aspx?ID=334
http://www.xyxyxyxyx.com/ShowProduct.aspx?ID=1094
and so on..
Recently I used IIS rewrite to rewrite this structure as
http://www.xyxyxyxyx.com/productcategory/334/my-product-url
http://www.xyxyxyxyx.com/productcategory/1094/some-other-product-url
and so on..
This works fine.
I want to create another rule so that if an invalid url requests comes with the following structure:
http://www.xyxyxyxyx.com/productcategory/ShowProduct.aspx?ID=334
the 'productcategory' part should be removed from the url and the url should look like
http://www.xyxyxyxyx.com/ShowProduct.aspx?ID=334
How do I write this rule?
It may vary depending on what you are using to apply the regex, but here's a basic one:
's|productcatgory/||'
If you want to make sure it also only does this when the xyxyxyxyx url is present, this should work:
's|^http://www\.xyxyxyxyx\.com/productcategory/|http://www\.xyxyxyxyx\.com/|'
Edit: Ah, so if productcategory could be any category, then you'll need to match around it, like so:
's|^http://www\.xyxyxyxyx\.com/.*/ShowProduct|http://www\.xyxyxyxyx\.com/ShowProduct|'

Rewrite rule with nginx replace get variable with slach

I've been reading everything i could find for two days now but nothing seems to work
I have an url like this
http://www.mysite.com/auction.php?category=23140
and want make a rewrite rule so it will appears like that
http://www.mysite.com/auction/category/23140.php
I do that only in order to build seo friendly url but so far nothing have worked.
rewrite ^/auction.php?category=(.*)$ /auction/category/$1 last;
It look so simple i realy don't know why it doesn't work.
Should i put this line in the server block or the location block ? Is the regex wrong ?
Any help will be greatly appreciated
At first, pls remember rewrite in nginx does not match query string, only uri.
For example, in this url: "/auction.php?category=23140", uri is /auction.php and query string is category=23140
So in your case, the correct rule should be:
if ( $request_uri ~ "^/auction\.php\?category=[0-9]+(.*)?$" ) {
rewrite "^.*$" /auction/category/$arg_category break;
}
Above is just a example, you can change it according to your case. And also you can find the usage of $request_uri and $arg_PARAMETER from the nginx manual.
You're doing it backwards, try this.
rewrite ^/auction/([^/]*)/([0-9]*) /auction.php?$1=$2
piece of advice, if this is a custom application you're writing without a framework, you could find a routing module that you could use and it would help you do every thing easily.

Need regex help for URL rewriting querystrings to friendly URLs

I updated my website CMS and the URL formats have changed. Where previously I had the URL /blog.aspx?Year=XXXX&Month=YY I now have /blog/XXXX/YY
Can someone help me create a regex for this?
Two additional notes:
it has to also support simply the year (/blog.aspx?Year=XXX)
the old Month urls use only 1 digit for single digit months (/blog.aspx?Year=2009&Month=2 instead of Month=02)
Here is what I came up with:
/blog.aspx[?]Year=([0-9]{4})([&]?)(Month=)?([0-9]*)
I can't seem to get it to work, as I still get a 404 on the page when I go to one of the above URLs.
Is this workable?
/blog.aspx\?Year=([0-9]{4})(?>\&?Month=?([0-9]{1,2})|)
works with these input
/blog.aspx?Year=1983&Month=2
/blog.aspx?Year=1983
/blog.aspx?Year=1983&Month=12
there is this (?>blabla|moomoo) syntax.
If it cant find blabla match, it will match moomoo
Though i suspect regex here is not the root problem, what CMS handles the redirect?

Intelligencia URL ReWriter mapping with regex

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

What is the name for that thing that lets part of the URL be an argument?

For example:
http://stackoverflow.com/questions/698627/ms-access-properties
The number is part of the URL but is an argument to the web app as opposed to other options like:
http://www.google.com/firefox?client=firefox-a&rls=org.mozilla:en-US:official
where all the args come after the '?'. I have used the second form before and I'm only trying to learn about the first form.
I'm sure I can find what else I need once I known what that's called so I can Google it.
URL Rewriting, generally.
Edit: Here is a good introduction to URL Rewriting.
Variables passed in the form of a URL are called the Query String. In a url like:
http://examples.com?a=b&c=d&e=f
The query string is ?a=b&c=d&e=f
In the Stackoverflow example, it uses URL Rewriting, specifically with MVC Routing to make 'pretty URLs'. There are other ways to do it in other languages. Some make use of Apache's mod_rewrite (example) while others parse the requested URI. In PHP a url like
http://example.com/index.php/test/path/info
can be parsed by reading $_SERVER['PATH_INFO'] which is /text/path/info.
Generally, they are using URL Rewriting to simulate the query string however. In the Stackoverflow example:
http://stackoverflow.com/questions/698711/what-is-the-name-for-that-thing-that-lets-part-of-the-url-be-an-argument
The important parts are the questions/698711. You can change the title of the question with impunity but the other two parts you cannot.
It's usually called the 'path info'.
That's just URL mapping. It lets you use pretty URLs instead of a large query string.
I believe the StackOverflow URL works that way because it is using MVC whereas your bottom example is using standard requests.
It is indeed done by URL rewriting.
Usually, web application frameworks do this automatically if you install it correctly on your server.
Check out CakePHP as an example.
It's called a URL parameter and uses the HTTP GET method. As others mentioned, it can be rewritten using URL rewriting so that the URL is easier to read and use. Some search keywords: "SEF URLs", "Apache Rewrite", "pretty URLs".

Resources