views:

498

answers:

1

I have http://thewebsite.com/blah/category/hello.html

We need to redirect any url with /blah/ to the root of the site so that the new url is http://thewebsite.com/category/hello.html

How can we do this with iis7? Thanks in advance.

Edit: I have just learned that our problem is not about 301-redirection but rather about url-rewrite. We are actually using wordpress with permalink /index.php/%category%/%postname%.html and the url goes this way : http://thewebsite.com/index.php/categoryname/hello.html. So using Url Rewrite on IIS7, how can we make the url to http://thewebsite.com/categoryname/hello.html? Thank you so much!

+1  A: 

You can use the URL rewrite module as Lex Li described - it's quite powerful. It's an add-on that you can download and install into IIS7. For this example though, you can also use the "HTTP Redirect" feature which is included out of the box.

You will need the "blah" directory to exist physically under the root directory of thewebsite.com. It can be empty, but it has to exist. It can be an ordinary directory; it doesn't have to be a virtual directory or an application.

From the left-hand tree view, select the "blah" directory, and then go to features view. Double-click the "HTTP Redirect" icon. Check the "Redirect requests to this destination" box, and type "http://thewebsite.com". Leave both of the checkboxes under "redirect behavior" unchecked. Under "status code", choose "Permanent (301)". Then click the "Apply" link under "Actions" at the right.

This will redirect everything under http://thewebsite.com/blah/ to the corresponding URL under http://thewebsite.com/. It will also work for subdirectories under "blah", such as your "category" example.

Richard Beier
by root directory, do you mean c:/inetpub/wwwroot/ ? or is it the virtual directory used by iis which is like c:/inetpub/wwwroot/blah/ ? Thanks for the answer.
Jronny
It's the root directory (physical path) of your whole site thewebsite.com. It's not the virtual directory. If you only have one site ("Default Web Site"), then it's probably c:\inetpub\wwwroot\. If you have multiple websites on your server, it's probably something different. You can find out by highlighting the site in the tree, going to features view, and clicking "basic settings" on the right. A dialog box pops up with a "physical path". That's what I'm referring to.
Richard Beier