Solved

ISAPI Rewrite (IIS7)

Posted on 2014-01-22
6
370 Views
Last Modified: 2014-01-27
Hi,

We need to do a 301 redirect for the following URL:

www.contoso.com/en/testing123.aspx

to remove the /en/ and to go to: www.contoso.com/testing123.aspx

Basically wanted to have something in place to remove the /en/ when this URL is used within the address. Is this possible and how? To avoid writing hundred of redirects.

Thanks in advance,

introlux
0
Comment
Question by:introlux
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:jaywales
ID: 39799797
you could just use something like http://www.isapirewrite.com/ to do that for example:

[ISAPI_Rewrite]

# Translate /testing123.aspx to /en/testing123.aspx

Or you could also use the following in your web.config file for the application/site:


<system.webServer>
  <rewrite>
 <rewriteMaps configSource=”myrewritemaps.config” />  
 <rules>
   <rule name=”Redirect rule1 for Redirects”>
 <match url=”.*” />
 <conditions>
   <add input=”{Redirects:{REQUEST_URI}}” pattern=”(.+)” />
 </conditions>
 <action type=”Redirect” url=”{C:1}” appendQueryString=”false” />
   </rule>
 </rules>  
   </rewrite>
</system.webServer>

Then create a new translation config file called "myrewritemaps.config" and add the following:

<rewriteMaps>
   <rewriteMap name=”Redirects”>
 <add key=”/testing123.aspx” value=”/en/testing123.aspx” />
   </rewriteMap>
 </rewriteMaps>

That should solve it!
0
 

Author Comment

by:introlux
ID: 39799880
This will only work on /en/testing123.aspx, what if another URL is used like /ene/again.aspx, then another /en/again2.aspx etc.

I would like to create a rule that removes the /en/ but sends the user to the required URL.

Hope that helps.

Regards,

introlux
0
 
LVL 1

Accepted Solution

by:
jaywales earned 500 total points
ID: 39799986
Replace my earlier code with this:

    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                 <rule name="RemoveEN" stopProcessing="true">
                   <match url="EN/(.*)" />
                   <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
                 </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

This will remove the EN folder from any url request for example

/en/dosomething1.aspx becomes /dosomething1.aspx
/en/imdifferent2.aspx becomes /imdifferent2.aspx

etc etc!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:introlux
ID: 39811468
Using your code, I changed it to a 301:

            <rewrite>
                <rules>
                 <rule name="RemoveEN" stopProcessing="true">
                   <match url="EN/(.*)" ignoreCase="true" />
                   <action type="Redirect" url="/{R:1}" appendQueryString="true" />
                 </rule>
                </rules>
            </rewrite>

All working! Thanks!
0
 

Author Closing Comment

by:introlux
ID: 39811470
Great!!
0
 
LVL 1

Expert Comment

by:jaywales
ID: 39811635
no problems glad to help :)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question