iis 7 url rewrite with preset paths - url

I'm trying to make something like this work in iis 7, or web config
request:
products.aspx?id=100
rewrite:
domain/products/mp3
Please note, I do not want redirection, for domain/products/mp3 is invalid path, I just want the url rewrite so the user sees this path but the server serves the actual request.
Can you help?

Can you use the URL Rewrite functionality from ASP.NET instead? That was built for that.
RouteTable.Routes.MapPageRoute("Test", "domain/products/{type}", "~/products.aspx");
Then in products.aspx you have to map from mp3 to 100 somehow, but I assume you have a db table for that anyway.

Related

ASP Classic - How to set up Permalinks. URL rewrite?

We have a web project which we are working on (Custom CMS). Have a url example http://www.test.com/page.asp?PID=191
Is there not an way to change this url into something like http://www.test.com/product-title/
Any help would greatly be appreciated.
An old method of doing this was to use custom error handling. Using a 404 custom error handling page you can trap a request to http://www.test.com/product-title/ pull it apart and build the request to the resource in this case http://www.test.com/page.asp?PID=191.
There are various ways of doing this from storing the values in a database so you can lookup your friendly address against it's equivalent to using the URL to describe the resource, something like http://www.test.com/products/191/ then using this as the basis of your rewrite.
In newer versions of IIS though (7 and above) you can use the URL Rewriting to build translation from one URL to another on the fly.
Links
URL Rewrite (download link)
Using the URL Rewrite Module

ASP.NET MVC server path is different from application path

I have an unusual circumstance where our web server inserts a folder into the url path before loading the page. Let me give you an example:
The app is called equipment and if I were to run it on a normal server setup, it would look like:
www.site.com\equipment\home\index
BUT when I run it on our server, it inserts "idn" in the url:
www.site.com\idn\equipment\home\index
The messes up my relative references. The MVC functions want to redirect to use "\equipment\" instead of "\idn\equipment\". This happens with Scripts.Render(), Return View(), etc.
Also, I can't hardcode the "idn" into my urls b/c then it is no longer relative and it won't work on my dev box or test servers b/c they don't have a "idn" subfolder in localhost.
I also tried functions such as Request.ApplicationPath and what not but none of them return the "idn" in the result.
Is there way to MVC to know that this "idn" was inserted into the url and account for it?
Thanks!
Create your application on the test/production server in the idn folder, then it all works.

Translating URL in .htaccess

Here's what I would like to do
Say I have a domain, www.mydomain.com
I have my coldfusion application in www.mydomain.com/myapp
There is a folder under myapp called x and under x is y
like this
wwwroot - myapp - x - y - index.cfm
So y's URL will be
www.mydomain.com/myapp/x/y
I want the users to type
http://www.mydomain.com/y
Then I want to translate that URL to
http://www.mydomain.com/myapp/?virtualFolder=y
But throughout the session I want the users to only see the original URL
Would you be able to tell me how I could achieve this, may be in .htaccess?
[IIS webserver, Coldfusion 10, shared hosting]
Thanks
you cant use .htaccess in iis its Apache only, iis (depending on the version) has a isapi plugin that can help you there, but if you are on shared hosting you probably wont have access it. You also wont be able to use the Application.cfc OnMissingTemplate method because generally only direct requests for .cfm[l] or .cfc pages are sent to ColdFusion to be processed.
The only way that I see you being able to accomplish what you want is to use the index.cfm to do your own redirecting.
so instead of
http://www.mydomain.com/y
you will have to do
http://www.mydomain.com/index.cfm/y
in your index.cfm file you will then parse the url parameter and and using cflocation with status code of 301 to redirect to the actual page.

Possible to have ampersands ("&") in URL BEFORE the query string?

My client is determined to have a page at /nfm&t so I made a directory named nfm&t with an index.html (to test) and that URL is still throwing a 404. So apparently it's not that easy.
Any ideas? Or is there a way to just redirect nfm&t to nfmt, so that the URL at least resolves?
This is a Windows server, by the way, which throws a wrench into how I'm used to doing redirects.
Turning on AllowRestrictedChars and enabling VersionCompatibility should do it.
Why would a Windows Server throw a wrench into how you do redirects? If you are using IIS 7, you can use URL Rewrite Module. It is built into IIS. If you are using IIS 6, there is ISAPI Rewrite, which is an external module. Both use the same syntax as mod_rewrite for Apache.
Do you have a /nfm directory? If you don't, try making one. Either way, put in a Default.aspx file and have it spit back at you the exact path it's trying to access. Chances are, when you have this here, it will go to example.com/nfm/Default.aspx and let you run something from there.
If you do get to that directory, then try redirection to example.com/nfm%26t and see if it works. If this still doesn't help it, then you're SOL
I tried this on my Snow Leopard ( OSX 10.6.2 ) workstation with Apache and it works. That is from Firefox 3.6. Looks like a Windows thing you are struggling with. Honestly I didn't think that would work without encoding but you never know until you try.
alt text http://www.vertigrated.com/images/so_screenshot.png
Or is there a way to just redirect
nfm&t to nfmt, so that the URL at
least resolves?
Sure. Make a general url handler and/or an error handler. When it encounters a url, if that url is equal to /nfm&t, then under the hood rewrite the context to whatever page you actually really want to return. Is this a good idea? Probably not. But it will work. Keith's answer suggests two ways to grab the url and do stuff, though you could also do this via a global asax file (being careful to execute an aspx page when you hit an error so it actually gets hit) if you're using .Net.

SEO friendly URLs with Delphi ISAPI

My customer wants me to get rid of the dll and ? & characters in the url and use SEO friendly urls.
How can I go about this URL - rewrite?
Currently I have something like:
http://www.ultimateholidayplanner.com/uhp.dll/AccList?PN=AccommodationSearch.htm
That needs to turn into something like:
http://www.ultimateholidayplanner.com/Accommodation/List.htm
Many thanks
Use II7 and download Microsoft URL rewrite module to change this behavior.
see Using URL Rewrite module
Regards
You don't need to change your code, you need just to use something like ISAPI_Rewrite
ISAPI extensions can be mapped to the extension ".*" creating a wildcard extension mapping, and so catching any and every request to the site/virtual-dir. (especially with 'check that file exists' unselected)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true
(if it might interest you: I found out working on xxm)

Resources