simulate a non existent folder with isapi

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 05 Feb 2013, 12:22

simulate a non existent folder with isapi

05 Feb 2013, 12:35

I'd like to know if it's possible to simulate a folder with a slash "/" with isapi rewrite.

For example, I'd like to have a product.aspx page that will match different products like these:

http://www.mysite.com/product.aspx?name=screwdrivers
http://www.mysite.com/product.aspx?name=wrenchs

These urls will appear like this once rewritten:

mysyte.com/screwdrivers/
mysyte.com/wrenchs/

Now, what I want is to have urls like this:

mysite.com/screwdrivers/search.aspx
mysite.com/screwdrivers/results-5-54-98 (5, 54 and 98 would be IDs results after a search)
mysite.com/wrenchs/search
mysite.com/wrenchs/results-53-56-9

These urls will point at a page called search.aspx in the root folder.


The problem I'm having is that as screwdrivers or wrenchs are not real folders, the app returns an error 404.

Is it possible to match this kind of urls that simulate a non existent folder? I don't want ASP.net to look for a real folder and I want to use a slash.

Many thanks.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: simulate a non existent folder with isapi

05 Feb 2013, 22:24

Hello,

There's no need to simulate the folder. Here are the rule you might use:

Code: Select all
RewriteEngine on
RewriteBase /

## redirecting product.aspx?name=XXXX to SEO friendly format
RewriteCond %{QUERY_STRING} ^name=([^&]+)$ [NC]
RewriteRule ^product\.aspx$ /%1/ [NC,R=301,L]

## loading content for mysyte.com/XXXXXX/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ /product.aspx?name=$1 [NC,L]

## redirecting product.aspx?name=XXXX to SEO friendly format
RewriteCond %{QUERY_STRING} ^name=([^&]+)$ [NC]
RewriteRule ^search\.aspx$ /%1/search [NC,R=301,L]

## loading content for mysyte.com/XXXXXX/search
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/search$ /search.aspx?name=$1 [NC,L]



However I do not understand situation with "mysite.com/screwdrivers/results-5-54-98 (5, 54 and 98 would be IDs results after a search)"

Regards
Andrew

User avatar
Posts: 4
Joined: 05 Feb 2013, 12:22

Re: simulate a non existent folder with isapi

07 Feb 2013, 02:28

Andrew, thank you a lot, solved it with your help.

I didn't know I could check for existing directories!

What could I do if I want to add another page called company.aspx to behave like product.aspx?

I mean, for example if I want to load:

mysite.com/screwdrivers

it should load product.aspx?=screwdrivers

but if I load mysite.com/Ford

it should load instead company.aspx?=Ford

I think I'll have to check first if there is any product called Ford first and then search in the companies table (by the way, I'm avoiding using directories like mysite.com/companies/Ford or mysite.com/products/screwdrivers, that would be easy, I'm trying to use both at the root).

How can I make this kind of redirection? Should I do this from .net instead?

Many thanks!

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: simulate a non existent folder with isapi

07 Feb 2013, 02:38

In this case ISAPI_rewrite wouldn't know where to rewrite back... to product or a company.
The best approach in this case - mapfiles. Please, see more in FAQ

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests