Shortening the context root of a store URL

Shortening the context root of a store's URL makes it easier for shoppers to remember a link and also improves visibility in search engine results.

About this task

You can shorten the URL for your store by modifying the context root. You can change the default site URL from http://hostname/webapp/wcs/stores/servlet/StoreName/index.jsp to something shorter, such as: http://hostname/shop/StoreName/index.jsp. In this example, shop is used to replace the context root, but any name can be used in its place, including a blank context root value.

WebSphere Commerce DeveloperTo shorten the context root of a store URL within your development environment, ensure that you have a web server that is configured to work with your environment. You must configure the web server to work with your environment before you begin. You can install and configure the IBM HTTP Server to work with development environment. For more information, see Installing IBM HTTP Server and Web Server Plug-ins.

Important: If there is an invalid protocol or timeout with a redirect, the redirected URL uses the full path, rather than the URL with the shortened context root.

Procedure

To modify the context root:
  • If you are running an IIS web server:
    1. Install the URL Rewrite module from:
      http://www.iis.net/download/URLRewrite
    2. Correcting the load order of IIS modules:
      1. Go to C:\Windows\System32\inetsrv\config.
      2. Open applicationHost.config
      3. Search for RewriteModule in the globalModules list.
      4. Move the line to above the IsapiFilterModule module in that list.
      5. Save the file.
    3. In the IIS Manager, select the server node and click Restart from the Actions list on the right side of the window.
    4. Restart the IIS Admin Service.
    5. Return to the server view in the IIS Manager.
    6. Double-click URL Rewrite.
    7. Create a rewrite rule to map the SEO URL to the original URL:
      1. Select Blank rule.
      2. Enter the following information into the form. In this example, shop is used to replace the context root. Any name can be used for the pattern:
        Name Enter a descriptive name, such as [SEORewriteRule]
        Pattern shop/(.*)$
        Ignore case checked
        Action type Rewrite
        Rewrite URL webapp/wcs/stores/servlet/{R:1}
        Append query string: checked
        Stop processing of subsequent rules: checked
      3. Click Apply.
  • If you are running an IBM HTTP Server:
    1. Go to WC_installdir/instances/demo/httpconf, where demo is your instance name
    2. Open httpd.conf
    3. Ensure that the following line is not commented out:
      LoadModule rewrite_module modules/mod_rewrite.so
    4. Locate the virtualhost object: <VirtualHost servername:80>. This object can display as <VirtualHost *:80>
    5. Insert the following code inside the <VirtualHost servername:80> object before the ending </VirtualHost> tag.
      RewriteEngine on 
      RewriteRule ^/shop/(.*) /webapp/wcs/stores/servlet/$1 [PT,L]
      If you are specifying a blank context root, use the following format instead:
      RewriteEngine on 
      RewriteRule ^/(?!wcsstore)(.*) /webapp/wcs/stores/servlet/$1 [PT,L]
      
      Using the preceding format when you are specifying a blank context root ensures that the storefront continues to function correctly. Otherwise, you might encounter errors with storefront CSS and images not displaying correctly.
    6. Repeat the preceding step for any other virtual host that your environment uses.
      For example, <VirtualHost servername:443> or <VirutalHost *:8006>.
    7. Save the file.
    8. Restart the IBM HTTP server.
  • If you are running a Sun web server:
    1. Go to the config directory where you installed your Sun web server.
      For example: /opt/webserver7/https-hostname/config
    2. Open the obj.conf file.
    3. Add the following entry inside the default Object tag:
      <If $uri =~ '^/shop/(.*)'>
      	NameTrans fn="restart" uri="/webapp/wcs/stores/servlet/$1"
      </If>
      
    4. Restart the web server.
    5. Optional: If you want to support having query parameters in your URL with the shortened context root, repeat steps 3 and 4 replacing the <If> block with the following code:
      <If $uri =~ '^/shop/(.*)' and not defined $query>
      NameTrans fn="restart" uri="/webapp/wcs/stores/servlet/$1"
      </If>
      <If $uri =~ '^/shop/(.*)' and defined $query>
      NameTrans fn="restart" uri="/webapp/wcs/stores/servlet/$1?$query"
      </If> 

What to do next

Once the rewrite rule is updated in the web server, update the WebSphere Commerce Server configuration file to provide the context root rewrite rule value:
  1. Open the WebSphere Commerce configuration file.
  2. Search for the SEOConfiguration section.
  3. Within the SEOConfiguration section, enter the following code:
    <context-root-rewrite value="/shop" />
    For example:
    <SEOConfiguration defaultUrl="" dynamicUrl="true" enable="true">
    <context-root-rewrite value="/shop" />
    </SEOConfiguration> 
  4. Save the file.
  5. Propagate the changes to the WebSphere Commerce configuration file.