[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 404
  • Last Modified:

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

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.
0
Webbo_1980
Asked:
Webbo_1980
  • 2
1 Solution
 
Brad HoweCommented:
hi,

http://your.domain.com/landingpage
to
http://your.domain.com/home?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName

Where are you pulling the highlights values from? As you mentioned above, this is fine for your action but the 500 error is the app processing.
<action type="Redirect" url="/home?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName" redirectType="Permanent" appendQueryString="false" />

You could also use static rewrites and hardcode those values.

<rewrite>
 <rewriteMaps>
  <rewriteMap name="StaticRewrites" defaultValue="">
    <add key="/landingpage" value="/home?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName" />
  </rewriteMap>
 </rewriteMaps>
</rewrite>
And a rewrite rule defined as follows:

<rewrite>
 <rule name="Rewrite Rule">
  <match url=".*" />
  <conditions>
   <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
  </conditions>
  <action type="Rewrite" url="{C:1}"/>
 </rule>
</rewrite>

The requested URL /landingpage will be rewritten as /home?utm_source=emailSignature&utm_medium=email&utm_campaign=campaignName.

Let me know if im misunderstanding. If so please provide more detail in to what you are trying to accomplish with URL examples :)

Cheers,
Hades666
0
 
Webbo_1980Author 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
0
 
Webbo_1980Author 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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now