We help IT Professionals succeed at work.

Setting up static 301 redirects in an ASP.NET project with extensionless URLs and parameters

429 Views
Last Modified: 2012-05-11
Hello,
I need to set up a static 301 redirects in my asp.net project (via the iis module) and am having some issues getting a tracking parameter to work.

This code works fine, but I need to add a tracking parameter to the end of the destination page:

  <system.webServer>
  …
      <rewrite>
          <rewriteMaps>
              <rewriteMap name="tracking" />
          </rewriteMaps>
          <rules>
              <rule name="1B" stopProcessing="true">
                  <match url="^landingpage" ignoreCase="false" />
                  <action type="Redirect" url="/home" redirectType="Permanent" appendQueryString="false" />
              </rule>
          </rules>
      </rewrite>
  …
  </system.webServer>

As soon as I add this -

?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName

as a parameter after /home, the entire site breaks giving a 500 error.

Does anyone know how I can successfully 301 redirect to url="/home?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName" via the config?  Pasting the url directly into the address bar does work, I just need to redirect to it via a friendly url.

Thanks in advance.
Comment
Watch Question

DevOps Manager
Top Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Hello,
Sorry, that doesn't help me in this case.

The parameters are used in analytics tracking.  Anyone visiting /landingpage will have only gotten there via a particular link (in this case, in an email), but we need to translate this into tracking parameters that Google can tie into the rest of the analytics (to tie in with purchases, adwords conversion rates, etc).

Can you confirm where in the web.config each of those sections should go?  Do they go in different sections?  I tried putting them both together and am getting the same problem.  The bizarre thing is that when this is in place, ALL pages give a 500 error, it's not just the /landingpage I'm trying to redirect, so the site is completely broken.

Ie, this is what I tried:

  <system.webServer>

      <rewrite>
          <rewriteMaps>
              <rewriteMap name="StaticRewrites" defaultValue="">
                  <add key="/landingpage" value="/home?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName" />
              </rewriteMap>
          </rewriteMaps>
          <rules>
              <rule name="Rewrite Rule">
                  <match url=".*" />
                  <conditions>
                      <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
                  </conditions>
                  <action type="Rewrite" url="{C:1}"/>
              </rule>
          </rules>
      </rewrite>

  </system.webServer>

Open in new window



The required outcome is exactly as you said:
The requested URL /landingpage will be rewritten as /home?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName.
But I just can't get it to work with the parameters.

Thanks

Author

Commented:
I've just had another thought, in the suggestions above, we're using rewrites - but does that mean the physical page /landingpage must exist?

What we're wanting to do is redirect to a page - ie, /landingpage doesn't actually exist - we want to display the /home content but with the added parameters.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.