Knowledge Base

The VMware Knowledge Base provides support solutions, error messages and troubleshooting guides
 
Search the VMware Knowledge Base (KB)   View by Article ID
 

Redirecting URL requests using the mod_rewrite module in Apache HTTP Server, vFabric Enterprise Ready Server, or vFabric Web Server (2009851)

Purpose

This article provides a sample usage of the mod_rewrite module for redirecting a URL request in Apache HTTP Server, vFabric Enterprise Ready Server, or vFabric Web Server. 

Resolution

Assume that the request is for http://www.example.com/oldpath/file.html and you want to redirect all requests under /oldpath/ to /newpath/, resulting in a redirect to http://www.example.com/newpath/file.html for this request.
 
To redirect the request:
  1. Open this server configuration file using a text editor:
    • For Apache HTTP Server or VMware vFabric Web Server – conf/httpd.conf
    • For vFabric Enterprise Ready Server – conf/httpsd.conf

  2. Add this entry to the file:

    RewriteEngine on
    RewriteRule ^/oldpath/(.*)$ /newpath/$1 [R=302,L]

    Where:
    • RewriteEngine on – Enables RewriteRule directives.

      When RewriteRule is disabled, mod_rewrite is inactive and is ignored. This is required only once in the configuration file.

    • RewriteRule –  Is the directive that transforms the request.

      It performs a substitution using a pattern match and replace, and may have other side effects.

    • ^/oldpath/(.*)$ – Is the regular expression or regex.

      The regex language is implemented with the PCRE (Perl-Compatible Regular Expression) lib. In this case, it directs to check the URI (the part after the host name) for the beginning ( /oldpath/) and capture everything after that.

    • /newpath/$1 – Is what the request URI will be changed to. The $1 stands for the text captured in the regex.

    • [R=302,L] – Are options for the rule.

      R=302 causes the new URI to be prepended with the host name. In this example, http://www.example.com is sent as the Location: header on a status 302 response. This is a temporary redirect and should not be cached by the browser. You can also use other status codes, such as 301 for a permanent, cacheable redirect.

      The L option indicates that when this rule matches, it is the last rule and no other rules are processed before sending the response.

Additional Information

You can also place mod_rewrite directives in directory-specific .htaccess files. But, you may need the RewriteBase directive for a correct resolution.

If you are using virtual hosts, be aware that, by default, mod_rewrite directives apply only to the host configuration in which the directives are located (the default host, if none is specified). It is possible to have virtual hosts inherit default host rules with the RewriteOptions inherit directive.

For more information on RewriteRule options and qualifiers, see:
For more information on URL rewriting, see the URL Rewriting Guide.
 
Note: The preceding links were correct as of February 08, 2012. If you find a link is broken, provide feedback and a VMware employee will update the link.

Request a Product Feature

To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.

Feedback

  • 0 Ratings

Did this article help you?
This article resolved my issue.
This article did not resolve my issue.
This article helped but additional information was required to resolve my issue.
What can we do to improve this information? (4000 or fewer characters)
  • 0 Ratings
Actions
KB: