Solved

ISAPI Rewrite (IIS7)

Posted on 2014-01-22
6
375 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 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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). …

687 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