Solved

ISAPI Rewrite (IIS7)

Posted on 2014-01-22
6
357 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:introlux
Comment Utility
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
Comment Utility
Great!!
0
 
LVL 1

Expert Comment

by:jaywales
Comment Utility
no problems glad to help :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Outlook Anywhere not working 3 55
SSRS 2012 URL 11 46
disable Win7 network security 2 73
2 websites hosted on premise 6 35
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…
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…
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…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now