Solved

ISAPI Rewrite (IIS7)

Posted on 2014-01-22
6
369 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
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). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

860 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