1

Noob question here. I searched, but couldn't quite find anything that would explain how to do this. I'm using IIS7 on a 2 server web farm with traffic being load balanced to either of the two servers.

I have a URL http://something./org that goes to page http://something.mydomain.com

On this page there is a hyperlink that users can click on that will take them to http://something.mydomain.com/search.

I would like to redirect users that go to http://somethingsearch.org/ to redirect them to http://something.mydomain.com/search

Is this possible? I'm thinking an ISAPI Rewrite Rule might be necessary to accomplish this, but I'm unsure.

Sorry if there's not enough information provided. I was just thrown this little task earlier today and they're looking for a quick turnaround. If there are any questions or any other information that you might need, let me know and I'll see if I can dig it up.

1

You can use the IIS URL Rewrite extension from Microsoft.

IIS URL Rewrite 2.0 enables Web administrators to create powerful rules to implement URLs that are easier for users to remember and easier for search engines to find. By using rule templates, rewrite maps, .NET providers, and other functionality integrated into IIS Manager, Web administrators can easily set up rules to define URL rewriting behavior based on HTTP headers, HTTP response or request headers, IIS server variables, and even complex programmatic rules. In addition, Web administrators can perform redirects, send custom responses, or stop HTTP requests based on the logic expressed in the rewrite rules.

IIS URL Rewrite is the equivalent of apache mod_rewrite for IIS.

  • Links come and go. As a result, SE prefers that answers contain an answer. A link to a resource is fine, however, it is preferred that a rundown of the solution that someone can follow be a part of the answer. Otherwise, this is better as a comment. – closetnoc Apr 10 '15 at 22:26
1

I have a rewrite rule that forces my site url to be prefixed with "http://www". This is mainly for google analytics. So if someone goes to http://mywebsite.com it will redirect them to http://www.mywebsite.com.

You can accomplish this in two ways:

  • Create the rewrite in IIS if you have IIS URL Rewrite installed. Here is how it is done:

Add a rewrite rule in IIS Manager

Match URL Section

  • Name the rule
  • Select "Matches the Pattern" under Requested URL:
  • Select "Regular Expressions" under Using:
  • Add this expression "^(.*)$"
  • Check "Ignore case"

    Match URL Section Screen Shot


Conditions Section

  • Set "Logical grouping" to "Match All"
  • Click the "Add" button
  • Enter "{HTTP_HOST}" for the Condition input
  • Select whether or not you want it to match the pattern (in my case I did not)
  • Enter the expression "^www.(.+)$"
  • Check "Ignore case"

    Add Condition


Action Section

  • Select "Redirect" for the Action type
  • Enter your redirect URL - in my case it was: "http://www.{HTTP_HOST}/{R:1}"
  • Check "Append query string"
  • Select "Permanent (301)" as the redirect type

enter image description here

Save the rule

  • If the site is a .NET site, edit the web.config to add the rule under the "system.webServer" section

    <rewrite>
      <rules>
        <rule name="wwwrewrite" enabled="true" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="true" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^www\.(.+)$" negate="true" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
    

Hope this helps....

  • Sorry for the delay here, things have been hectic and this got passed off to a different team member. I know he hasn't quite gotten it figured out yet, but I'm going to share this with him so he knows about it. What you've got there is a little different than what we're trying to do, but I think the concept is still the same and this may aid in coming to the final solution. I'll post an update once we do have a solution, but either way, I'd like to thank you for your time and assistance! I love the internet. Less all the YouTube trolls and bigots, it's generally a very friendly place :) – Fernando Vega May 8 '15 at 17:41
1

My co-worker that took this over was able to come up with a solution that worked for us on this one. Just figured I'd post to close the loop on this one so if anyone else runs into a similar issue, it might help them out as well.

He wrote an ISAPI ReWrite/ReDirect rule using the ISAPI ReWrite Manager for ISS that looks like this:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.org$

RewriteRule ^(.*)$ http://something.domain.com/Search [I,O,RP,L]

This is very much in line with what you folks were saying, but the issue he ran into was with trying to maintain the same URL http://something.org while redirecting to a subdirectory within the site.

So, he just said to hell with it and redirected to a different URL with the sub-directory included.

Thanks all for your input!!

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.