?
Solved

ISAPI Rewrite (IIS7)

Posted on 2014-01-22
6
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is an ISAPI filter?   •      It's an assembly (.dll file) that can add or change the way IIS works.   •      They can be enabled globally for your web server or on a site-by-site basis.   When the IIS server receives a request, enabling the ISAPI fi…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
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…

777 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