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.To 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:
-
Install the URL Rewrite module from:
http://www.iis.net/download/URLRewrite
-
Correcting the load order of IIS modules:
- Go to C:\Windows\System32\inetsrv\config.
- Open applicationHost.config
- Search for RewriteModule in the globalModules list.
- Move the line to above the IsapiFilterModule module in that list.
- Save the file.
-
In the IIS Manager, select the server node and click Restart from the
Actions list on the right side of the window.
-
Restart the IIS Admin Service.
-
Return to the server view in the IIS Manager.
-
Double-click URL Rewrite.
-
Create a rewrite rule to map the SEO URL to the original URL:
- Select Blank rule.
- 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 |
- Click Apply.
-
If you are running an IBM HTTP Server:
-
Go to WC_installdir/instances/demo/httpconf, where
demo is your instance name
-
Open httpd.conf
-
Ensure that the following line is not commented out:
LoadModule rewrite_module modules/mod_rewrite.so
-
Locate the
virtualhost
object: <VirtualHost
servername:80>
. This object can display as <VirtualHost *:80>
-
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.
-
Repeat the preceding step for any other virtual host that your environment uses.
For example, <VirtualHost servername:443>
or <VirutalHost
*:8006>
.
-
Save the file.
-
Restart the IBM
HTTP server.
-
If you are running a Sun web server:
-
Go to the config directory where you installed your Sun web server.
For example:
/opt/webserver7/https-hostname/config
-
Open the obj.conf file.
-
Add the following entry inside the
default
Object tag:
<If $uri =~ '^/shop/(.*)'>
NameTrans fn="restart" uri="/webapp/wcs/stores/servlet/$1"
</If>
-
Restart the web server.
- 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:
- Open the WebSphere Commerce configuration file.
- Search for the
SEOConfiguration
section.
- 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>
- Save the file.
- Propagate
the changes to the WebSphere Commerce configuration file.