Connect Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Friday, 13 July 2012

Importing Apache mod_rewrite Rules

Posted on 13:55 by Unknown

Introduction:


The Internet Information Services 7 (IIS 7) URL Rewrite Module provides an import feature that greatly simplifies the process of converting Apache mod_rewrite rules to IIS URL rewrite rules. In this walkthrough, you use the Import Rules feature provided in the URL Rewrite Module to import several mod_rewrite rules into an IIS configuration file. If you have not yet downloaded the URL Rewrite Module, you can do so at http://www.iis.net/download/urlrewrite.


Set Up A Walk-hrough Scenario:


To see how you can convert mod_rewrite rules and verify that the converted rules work correctly, you will implement the common scenario of enforcing canonical host names for a Web site. In this example, you will force the use of www.mysite.com instead of mysite.com, so that when a request is made that uses a host name other than www.mysite.com, you can redirect the request to a canonical host name.

1. Start IIS Manager, and then click Default Web Site.

2. In the Actions pane, click on Bindings, and add a new http binding for port 8088.



Figure 1: Add a new binding



3. Using Notepad, open %SystemDrive%\windows\system32\drivers\etc\hosts and add the two following lines at the end of the file:
127.0.0.1 www_mysite_com
127.0.0.1 mysite_com

Notice that you are using “_” instead of “.” for domain separators. This is to prevent the Web browser from trying to resolve the domain name by using a Domain Name System (DNS) server. 

4. Save the hosts file.

5. Verify that the host names were setup correctly by opening a Web browser and going to the sites http://www_mysite_com/iisstart.htm and to http://mysite_com/iisstart.htm.


Convert mod_rewrite Rules:

The Apache mod_rewrite rules to use for enforcing canonical host names are:
#For sites running on a port other than 80:
RewriteCond %{HTTP_HOST}   !^www_mysite_com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www_mysite_com:%{SERVER_PORT}/$1 [L,R]

#And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^www_mysite_com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www_mysite_com/$1 [L,R]


To convert these rules to IIS URL rewrite–specific format:

1. Start IIS Manager.


2. On the left, in the Connections pane, select Default Web Site.

3. On the right, in Features View, click URL Rewrite.



Figure 2: Click URL Rewrite



4. On the right, in the Actions pane, click Import Rules. 

5. Copy the example mod_rewrite rules above and past them into the Rewrite rules text box.




Figure 3: Rules to import




6. The Tree View tab of the Converted Rules box instantly shows the result of the conversion. You can also click the XML View tab to see how the rules are stored in the Web.config file.




Figure 4: Converted rules



If you switch back to Tree View and select a node there, the corresponding mod_rewrite rule directive in the Rewrite rules text box will be highlighted.





Figure 5: Tree view



Note that during the rules conversion the rules were assigned default names. To change the default names to something more meaningful, select a rule in Tree View, right-click it, and select Rename from the context menu.





Figure 6: Rename




Change the name of the first rule from ImportedRule1 to Redirect to www_mysite_com:non-80. Change the name of the second rule from ImportedRule2 to Redirect to www_mysite_com:80.

In the Actions pane, click Apply to save the converted rules to the Web.config file, and then click Back to rules.




Figure 7: Back to Rules


Test the Converted Rules:

To test that the rules imported from mod_rewrite format work correctly, open a Web browser, and go to either one of the following URLs:

http://localhost/iisstart.htm 
http://mysite_com/iisstart.htm

In both cases, the Web browser is redirected to 
http://www_mysite_com/iisstart.htm.

Also, if you try either of these URLs:

http://localhost:8088/iisstart.htm
http://mysite_com:8088/iisstart.htm

The Web browser gets redirected to http://www_mysite_com:8088/iisstart.htm.



Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • How to schedule a PHP script in task scheduler
    Quiet often there is a need to execute/run  php  script on some time interval at server side. And that php scripts should run automatically ...
  • HTTP Error 403.19 – Forbidden The configured user for this application pool does not have sufficient privileges to run CGI applications.
    If you get the error “HTTP Error 403.19 – Forbidden The configured user for this application pool does not have sufficient privileges to...
  • Roles and Features showing an error HRESULT: 0x800F0818 in Server Manager of windows server 2008 R2
    When you open Server Manager both Roles and Features display Error and you are unable to add any role or features. When you select the det...
  • Error - "Failed to retrieve data for this request (Microsoft.SqlServer.Management.sdk.sfc)"
    ErrError    - In Microsoft SQL Management Studio 2008, you receive the following error message when you try to expand the Databases:      ...
  • How to configure IIS 7 to redirect non-www domain to www domain?
    One of few legacy leftovers that was never dropped over the years is the common use of www domain prefix. It is not a problem per se for us...
  • Back up all MS SQL databases at once
    This article will discuss how to backup all MS SQL databases with one script. A separate file will be created for each database. Log into ...
  • The media family on device is incorrectly formed. SQL Server cannot process this media family Error: 3241
    When you try to restore a backup of the database you get the following error: The media family on device ” is incorrectly formed. SQL Server...
  • How to check Malware injection in Code
    To check Malware injection in your script/Code you can use a Web based Google Tool called “Webmasters Tools” You can find it here Google We...
  • An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
    If you are facing the following error while accessing the website: Error Summary HTTP Error 500.24 - Internal Server Error An ASP.NET settin...
  • Stopping Unneeded Services In Windows Server 2008
    By  default Windows 2008 starts with a number of services that actually do not need to be running. Many of these services can impact perfo...

Categories

  • booting Process
  • linux
  • redhat

Blog Archive

  • ►  2013 (68)
    • ►  July (1)
    • ►  May (2)
    • ►  April (11)
    • ►  March (54)
  • ▼  2012 (44)
    • ►  September (20)
    • ►  August (1)
    • ▼  July (4)
      • How to install ASP.NET 1.1 with IIS7 on Windows 2008
      • Translate .htaccess Content To IIS Web.config
      • Using the Microsoft Web Platform
      • Importing Apache mod_rewrite Rules
    • ►  June (12)
    • ►  May (2)
    • ►  March (4)
    • ►  February (1)
  • ►  2011 (1)
    • ►  February (1)
  • ►  2009 (9)
    • ►  September (3)
    • ►  August (2)
    • ►  June (1)
    • ►  May (2)
    • ►  March (1)
Powered by Blogger.

About Me

Unknown
View my complete profile