Jump to content
Sign in to follow this  
maxxd

web.config redirect rules

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.

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

Thanks much for your time, unfortunately this returned a 500 internal error.

 

Don't know if it makes a difference, but the site is hosted on GoDaddy.

Share this post


Link to post
Share on other sites

What does the error log say?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

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.