How to redirect to a specific page in web.config

Hi Experts,

Our website was originally called guy4senate.com and currently uses the following web.config file to essentially rebrand the site as the1stdistrict.com

<?xml version="1.0" encoding="UTF-8"?>
        <configuration>
			
            <system.webServer>
			
				<rewrite>
					<rules>
						<clear />
												
						<rule name="rebranding" enabled="true" stopProcessing="true">
							<match url="(.*)" />
							<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
								<add input="{HTTP_HOST}" pattern="(.*)guy4senate.com(.*)" />
							</conditions>
							<action type="Redirect" url="http://{C:1}the1stdistrict.com{C:2}/{ToLower:{R:1}}" appendQueryString="true" />
						</rule>
					</rules>
				</rewrite>
                
				<httpRedirect enabled="false" destination="http://www.the1stdistrict.com/blog" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
                
				<httpErrors errorMode="Custom">
                    <remove statusCode="404" subStatusCode="-1" />
                    <error statusCode="404" prefixLanguageFilePath="" path="/index.html" responseMode="ExecuteURL" />
                </httpErrors>
				
            </system.webServer>
            <location path="index.html">
                <system.webServer>
                    <httpRedirect enabled="true" childOnly="false" httpResponseStatus="Permanent" />
                </system.webServer>
            </location>
            <system.web>
                <customErrors>
                    <error redirect="/index.html" statusCode="404" />
                </customErrors>
            </system.web>
            <location path="aboutguy.asp">
                <system.webServer>
                    <httpRedirect enabled="true" httpResponseStatus="Permanent" />
                </system.webServer>
            </location>
            <location path="development.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="dollarsinpolitics.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="education.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="efficiency.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="endorsements.asp">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="independent.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="takeaction.asp">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
        </configuration>

Open in new window


We've recently added an additional domain name called vote4guy.com that we would like to have redirected to a specific page on our site called /vote4guy.html

(We set up domain forwarding on the domain record for vote4guy.com to point to the the1stdistrict.com).

I tried to set up a redirect rule for anyone that comes into the site with vote4guy.com to be redirected to the /vote4guy.html page, and all other site visitors to continue to be redirected to the1stdistrict.com/blog page as the web.config originally had, but it seemed to just ignore my entry:

						<rule name="vote4guy" enabled="true" stopProcessing="true">
							<match url="(.*)" />
							<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
								<add input="{HTTP_HOST}" pattern="(.*)vote4guy.com(.*)" />
							</conditions>
							<action type="Redirect" url="http://{C:1}the1stdistrict.com{C:2}/vote4guy.html" appendQueryString="true" />
						</rule>
						
						<rule name="rebranding" enabled="true" stopProcessing="true">
							<match url="(.*)" />
							<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
								<add input="{HTTP_HOST}" pattern="(.*)guy4senate.com(.*)" />
							</conditions>
							<action type="Redirect" url="http://{C:1}the1stdistrict.com{C:2}/{ToLower:{R:1}}" appendQueryString="true" />
						</rule>

Open in new window


Can anyone help me with the correct syntax that will redirect any site visitor who enters the site with vote4guy.com (or www.vote4guy.com) to be redirected to www.the1stdistrict.com/vote4guy.html, while leaving all other visitors who come to the site to be redirected to the1stdistrict.com/blog as usual?

thanks experts!
LVL 1
rascalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

becraigCommented:
            <rule name="vote4guy">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www\.vote4guy\.com$" negate="true" />
                </conditions>
		  <action type="Redirect" url="http://{C:1}the1stdistrict.com{C:2}/vote4guy.html" appendQueryString="true" />
            </rule>

						<rule name="rebranding" enabled="true" stopProcessing="true">
							<match url="(.*)" />
							<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
							<add input="{HTTP_HOST}" pattern="^www\.guy4senate\.com$" negate="true" />
							</conditions>
							<action type="Redirect" url="http://{C:1}the1stdistrict.com{C:2}/{ToLower:{R:1}}" appendQueryString="true" />
						</rule>

Open in new window

0
rascalAuthor Commented:
I tried the entry above, but received a 500 server error:

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

The page does exist and is displayable if you manually type in the address: http://www.the1stdistrict.com/vote4guy.html
0
rascalAuthor Commented:
One further note on the test above: even though the 500 error was received, the page address in the browser still went to the the1stdistrict.com/blog address so it seems like the first rule was either ignored, or the logic then fell through to the 2nd rule for the /blog/ address.
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

becraigCommented:
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

This should give you what you need to understand URL rewrites as well
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rascalAuthor Commented:
Thanks all, I've read through the docs, and even used the IIS manager GUI to set the values for the redirect to help ensure that my syntax is correct, but no matter what I enter, the user is always redirected to the /blog/ folder.

vote4guy.com, guy4senate.com and the1stdistrict.com all have the same IP address by the way, the actual website is running IIS, with a PHP handler that handles the WordPress blog in the /blog/ folder.

The desired effect is that whenever anyone types in http://www.vote4guy.com, that they be redirected to http://www.the1stdistrict.com/vote4guy.html. But in every case, they are always redirected to http://www.the1stdistrict.com/blog

What could I possibly be doing wrong?

Below is my complete web.config

<?xml version="1.0" encoding="UTF-8"?>
        <configuration>
			
            <system.webServer>
			
				<rewrite>
					<rules>
						<clear />
						
						<rule name="voteforguy" enabled="true" stopProcessing="true">
							<match url="(.*)vote4guy.com(.*)" />
							<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}" pattern="(.*)vote4guy.com(.*)" />
							</conditions>
							<action type="Rewrite" url="http://www.the1stdistrict.com/vote4guy.html" appendQueryString="true" />
						</rule>
																
						<rule name="rebranding" enabled="true" stopProcessing="true">
							<match url="(.*)" />
							<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
								<add input="{HTTP_HOST}" pattern="(.*)guy4senate.com(.*)" />
							</conditions>
							<action type="Redirect" url="http://{C:1}the1stdistrict.com{C:2}/{ToLower:{R:1}}" appendQueryString="true" />
						</rule>
					</rules>
				</rewrite>
                
				<httpRedirect enabled="false" destination="http://www.the1stdistrict.com/blog" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
                
				<httpErrors errorMode="Custom">
                    <remove statusCode="404" subStatusCode="-1" />
                    <error statusCode="404" prefixLanguageFilePath="" path="/index.html" responseMode="ExecuteURL" />
                </httpErrors>
				
            </system.webServer>
            <location path="index.html">
                <system.webServer>
                    <httpRedirect enabled="true" childOnly="false" httpResponseStatus="Permanent" />
                </system.webServer>
            </location>
            <system.web>
                <customErrors>
                    <error redirect="/index.html" statusCode="404" />
                </customErrors>
            </system.web>
            <location path="aboutguy.asp">
                <system.webServer>
                    <httpRedirect enabled="true" httpResponseStatus="Permanent" />
                </system.webServer>
            </location>
            <location path="development.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="dollarsinpolitics.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="education.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="efficiency.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="endorsements.asp">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="independent.html">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
            <location path="takeaction.asp">
                <system.webServer>
                    <httpRedirect enabled="true" />
                </system.webServer>
            </location>
        </configuration>

Open in new window

0
becraigCommented:
Can you send me a fiddler trace on the each call so we can identify what is happening when you load the URLs, it will help us to isolate what might be wrong.


You can get fiddler at http://www.fiddlertool.com
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.