+

Search Tips   |   Advanced Search

Provide short vanity URLs using web server rewrite rules


Overview

We can create vanity URLs that contain only the vanity segment by omitting the string /wps/vanityurl. In this case, we must use a web server/a> and define a rewrite rule. If we also use IBM Web Application Bridge, or if we have static files in the root of the HTTP server document directory, adapt the rewrite rule accordingly.


Define a rewrite rule

For the IBM HTTP Server...

  1. Open the file httpd.conf with an editor.

  2. Activate the following modules:

      proxy_module
      proxy_http_module
      rewrite_module

  3. Activate the rewrite engine by adding the following line:

      RewriteEngine On

  4. Add the rewrite rule by adding the following line:

      RewriteRule ^/([^/]+)$ /wps/vanityurl/$1 [P]

    This rule redirects all single path requests to the vanity URL servlet. The P flag at the end of the line tells the rewrite engine to use a proxy request. This flag is required for the IBM WebSphere Application Server plug-in to handle the request without an extra redirect.

  5. Optional: If our website editors work in projects and we want them to be able to use short vanity URLs by the HTTP server, we need an extra rewrite rule as follows:

      RewriteRule ^/\$project/([^/]+)/([^/]+)$ /wps/vanityurl/\$project/$1/$2 [P]

    This rule rewrites all URLs that start with /$project/project name/vanity name.

  6. Optional: The rules that are given in the previous steps might prevent static files in the document directories of our HTTP server from being served.

    To have them served, add conditions before the rewrite rule as in the following example:

      RewriteCond     %{DOCUMENT_ROOT}%{REQUEST_FILENAME}     !-f
      RewriteCond     %{DOCUMENT_ROOT}%{REQUEST_FILENAME}     !-d
      RewriteCond     %{DOCUMENT_ROOT}%{REQUEST_FILENAME}     !-l

    In this example...

    • f means file
    • d means directory
    • l means symbolic link

    With these conditions added, the portal does not apply the rewrite rule on requests that match a file, directory, or symbolic link. The user accesses the file, directory, or link and is not redirected to the target website of the vanity URL. See the information under Apache Module mod_rewrite.

    Best practice is to not use periods in vanity URLs to avoid conflicts with files in the HTTP server context root.

  7. Optional: For Web Application Bridge, add a rewrite rule to avoid namespace conflicts.

    Web Application Bridge must be mapped to the root context. As a result, vanity URLs and Web Application Bridge are in the same namespace, which can result in conflicts. Therefore, if we use Web Application Bridge, we might also define a more specific rewrite rule than the rule given earlier. Example:

      RewriteRule ^/([^/\.]+)$ /wps/vanityurl/$1 [P]

    With this rewrite rule, the portal redirects only names that consist of only one segment and contain no periods. This rewrite rule avoids conflicts with file names, such as shoe_sale.html. For project work, modify the rule as required.

  8. Configure the preview link in the vanity URL user interface to show the short vanity URL.

    The user interface for managing vanity URLs has a preview link. By default, this link goes directly to the vanity servlet, and the portal shows the full vanity URL, for example...

      http://hostname/wps/vanityurl/shoe-sale

    We can configure the preview link to point to the HTTP server instead, which shows the short version of the vanity URL. To configure the preview link target, we use the portal configuration task...


Parent topic: Administering vanity URLs

Related

  1. Integrating with web applications
  2. Preparing a remote web server
  3. Configuring the vanity URL preview link
  4. IBM HTTP Server
  5. Apache mod_proxy