PDA

View Full Version : Using Rewrite function in Web.config to redirect a url to a subdirectory


jbm123
03-29-2011, 07:07 PM
I rewrote the code supplied by nuclearspike in a previous post to redirect a url to a subdirectory in the root of my hosted domain. The placed the Web.config file containing the code (shown below) in the root directory. I purchased a domain pointer for the redirected url (thebitplayers.net).

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<rewrite>
<rules>
<rule name="thebitplayers_net" stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?thebitplayers.net"/>
<add input="{PATH_INFO}" pattern="^/BitPlayers/" negate="true"/>
</conditions>
<action type="Rewrite" url="\thebitplayers\{R:0}"/>
</rule>
</rules>
</rewrite>
</system.web>
</configuration>

When I try to access any site in my hosted domain containing the Web.config file I get the following HTTP error message (500.19):

Module IIS Web Core
Notification Unknown
Handler Not yet determined
Error Code 0x80070032
Config Error The configuration section 'rewrite' cannot be read because it is missing a section declaration
Config File \\?\E:\web\newportlive\htdocs\web.config
Requested URL http://www.thebitplayers.net:80/
Physical Path
Logon Method Not yet determined
Logon User Not yet determined

Any suggestions?

Tasslehoff
03-30-2011, 07:03 AM
The following link may help you:

http://msdn.microsoft.com/en-us/library/ms972974.aspx

Tasslehoff
03-30-2011, 07:56 AM
Sorry, I went to look up nuclearspike's post. Change

<system.web>
</system.web>

to

<system.webServer>
</system.webServer>

This is what the URL Rewrite module creates if you follow the instructions in the blog.

keikoraca
03-30-2011, 12:51 PM
You may also want to take a look at this URL (http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/) from Microsoft's IIS site.

It covers many of the basics and offers some step-by-step instructions including sample code for the URL re-write module.