Jump to content

web.config redirect rules


maxxd

Recommended Posts

Hey y'all.

 

I just went live with a client site yesterday - I had written the .htaccess rules to redirect any existing bookmarks to the corresponding new pages, tested those, and was ready to go. Then, lo and behold, the client's on an IIS 7 server. I haven't looked at IIS in years and am now having some issues with attempting to translate the Apache redirects to IIS redirects.

 

It should be told that the site is a WordPress site, and I got the rewrite rule working as expected.

 

Back to the redirects, I've tried the following in the rewrite.rules node of my web.config file:

<rule name="contractors">
	<match url="^contractors\.html$"/>
	<action type="Redirect" url="contractors/" appendQueryString="false" redirectType="Permanent"/>
</rule>

I've also tried:

<rule name="contractors">
	<match url="^(.*)"/>
	<conditions>
		<add input="{URL}" pattern="contractors.html"/>
	</conditions>
	<action type="Redirect" url="contractors/" appendQueryString="false" redirectType="Permanent"/>
</rule>

There was another method that involved the definitions in a separate file and linking to that from within the web.config as a map of sorts that I tried (I'm sorry, I'm a bit fried by it all and I tried this method yesterday and ditched the code when it didn't work).

 

Neither of the above quoted code blocks actually did anything. By that I mean that visiting //myclientsite/contractors.html served a 404 page instead of redirecting to //myclientsite/contractors/ as expected. There were some other variations that immediately caused a server 500 fault, so I know the web.config is being touched each time the page is refreshed (please see earlier disclaimer when considering the fact that I've not quoted the variations...).

 

Anyone have any ideas/suggestions/swift kicks to the head about where I may be going wrong? Many thanks in advance.

Link to comment
Share on other sites

Try something like this:

<rewrite>
    <rules>
        <rule name="Old Contractors" patternSyntax="ExactMatch" stopProcessing="true">
            <match url="contractors.html" />
            <action type="Redirect" url="/contractors/" appendQueryString="false" type="Permanent" />
        </rule>
    </rules>
</rewrite>
Link to comment
Share on other sites

According to tech help, apparently IIS doesn't actually create an error log. Which is awesome. I'm doing some digging into how to enable verbose error messages, I just hate doing that on a production server, even for a short amount of time.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.