2

I have a content managed ASP.NET site that runs the same version of the site in different languages (e.g. mysite.com, mysite.fr, mysite.eu, etc). I have been asked to create a redirect from one page on our French site to a page on our European site, so I fired up URL Rewrite within IIS and attempted to write a rule and map to do this. After failing this I attempted to write it into the Web.config file, but again to no avail.

To be clear, I need:

  • http://www.mysite.fr/publication/jobs.aspx to redirect to http://www.mysite.eu/jobs.aspx
  • http://www.mysite.fr/sign-in.aspx to redirect to http://www.mysite.eu/sign-in.aspx.

Does anyone know exactly how I can do this or whether this can be done on a ASP.NET site with multiple domains?

2
  • have you tried using Global.ascx file's Application_BeginRequest event for rewriting url? Apr 5, 2012 at 9:07
  • I have, but as my site is content managed I am unable to provide valid virtual URL's.
    – AlexT
    Apr 5, 2012 at 9:43

1 Answer 1

2

You can do this using URL Rewrite.

Here's an example that I use.

<rule name="Redirect .co.uk" stopProcessing="true">
  <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
     <add input="{HTTP_HOST}" pattern="^uk\.test\.com$" />
    </conditions>
  <action type="Redirect" url="http://www.test.co.uk/{R:1}" />
</rule>

This will check the the {HTTP_HOST} of the request, if it matches uk.test.com, redirect to the new url but keep the page/folder path ({R:1}).

Adding /publication/ makes things a little trickier, but it can be written into the original match (something like. (.*)\/publication\/(/*) or something, my Regex aren't perfect :-)).

HTH

2
  • This is almost exactly what I have already used, although I am only redirecting one page and it looks like this code doesn't have a mapping to target this page.
    – AlexT
    Apr 5, 2012 at 10:28
  • Can you edit your question to include the URL Rewrites you've already tried, please?
    – ianbailey
    Apr 5, 2012 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.