Develop > Presentation layer > Search engine optimization (SEO)
Optimize the site for search engines
You can optimize the site for search engines, using techniques to make the site easier to index by a search engine.
Before you begin
- Verify the JSP pages can use search engine optimization. To facilitate optimization of Web page locations that are given more weight by search engines when ranking search results, use the tools described in Update page content.
- If we will use the provided Perl scripts to convert dynamic URLs in JSP pages to static URLs, ensure that the target system has Perl version 5.6 or higher installed, along with the following Perl modules:
- HTML::Parser
- URI::URL
- XML::XPath
- File::Find
- File::Path
- Cwd
Procedure
- Ensure that you are logged in as the wc_user created before installing WebSphere Commerce (wasuser_ID by default).
- Enable URL mapping.
- Open the WebSphere Commerce configuration file.
- Verify the UrlMapperConfig component is enabled, as shown in the following example:
<component compClassName="com.ibm.commerce.datatype.UrlMapperConfig" enable="true" name="UrlMapperConfig"> <property UrlMapperFile="mapper/SEOUrlMapper.xml" display="false" /> </component>
- Deploy the updated WebSphere Commerce configuration file.
- Identify the JSP pages that you want the search engine to index. Usually, these are catalog-related pages such as ProductDisplay and CategoryDisplay.
- Optional: Create a site map.
You can now perform any further optimization, including conversion to static URLs in step 7, on the site map pages in place of the original pages.
- Create a subdirectory for the site map pages; for example:
- workspace_dir\Stores\Web Content\store
- Copy each of the JSP pages that you identified in step 3, as well as any pages included in them, into the SiteMap subdirectory.
- Add URL mappings to the URL mapping file.
Open the SEOUrlMapper.xml file. Its location is specified in the WebSphere Commerce configuration file and defaults to the WC_EAR/xml/mapper directory.
If you are using a site map, specify the location of the site map subdirectory with the subDirectory attribute of the pathInfo_mappings element. For example:
<pathInfo_mappings separator="_" subDirectory="SiteMap">WebSphere Commerce adds the subDir=SiteMap name-value pair, which indicates that the site map JSP pages are located in the SiteMap directory, to the set of properties associated with the current request.
- Create or modify a pathInfo_mapping element for each command associated with the JSP pages that you identified in step 3. Typically these commands are:
For the ProductDisplay command, for instance,
webapp/wcs/stores/servlet/ProductDisplay?storeId=10001&catalogId=10001&productId=10032&langId=-1
should map to
<mappings><pathInfo_mappings separator="_" ... > <pathInfo_mapping name="product" requestName="ProductDisplay"> <parameter name="storeId" /> <parameter name="catalogId" /> <parameter name="productId" /> <parameter name="langId" /> </pathInfo_mapping> ... </pathInfo_mappings> </mappings>
- The recommended separator is an underscore (_) . Use forward slash (/) as a separator if all the JSP pages use absolute paths when referencing URLs and images. Examples of absolute and relative path are...
- absolute path
- <a href="/webapp/wcs/stores/servlet/CategoryDisplay?storeId=10001 ... >
- relative path
- <a href="CategoryDisplay?storeId=10001 ... >
- Avoid using reserved URL characters such as &, +, :, ?, and ; when setting the separator. These reserved characters have special meanings and can result in the web server and application server improperly processing these characters.
While the hexadecimal values of such characters (such as using %3a to represent the : character, etc.) can appear to yield satisfactory initial results, unexpected errors can still occur over additional applications of its same usage. Therefore, you should use the recommended separators when setting the separator.
- If you are using a site map, set up separate caching for the site map pages by adding a component element with the ID of subDir to the site's cachespec.xml file for each command associated with the JSP pages that you identified in step 3. As an example, the portion of the cachespec.xml file that pertains to the TopCategoriesDisplay command should now look...
<!-- TopCategoriesDisplay?storeId=<storeId>&catalogId=<catalogId> --> <cache-id> <component id="" type="pathinfo"> <required>true</required> <value>/TopCategoriesDisplay</value> </component> <component id="storeId" type="parameter"> <required>true</required> </component> <component id="catalogId" type="parameter"> <required>true</required> </component> ... <component id="subDir" type="parameter"> <required>true</required> </component> <component id="DC_lang" type="attribute"> <required>true</required> </component> <component id="DC_curr" type="attribute"> <required>true</required> </component> ... </cache-id>
- Convert JSP pages with dynamic URLs to JSP pages with static URLs using any of the following methods:
- URL Mapping Perl Script for standard JSP (urlmapping.pl)
This will convert a:href url syntax such as:
CategoryDisplay?catalogId=<%=catalogId%>&categoryId=<%=category.getCategoryId()%>&storeId=<%=storeId%>
to
Category_<%=catalogId%>_<%=storeId%>_<%=category.getCategoryId()%>
Prerequisite: Perl application is installed and executable on the machine Command syntax:
perl WC_INSTALL/samples/urlmapping/bin/urlmapping.pl URL_Mapping_File target_directory starting_directory
or
perl WC_INSTALL/samples/urlmapping/bin/urlmapping.pl URL_Mapping_File target_directory file
Parameters:
- URL_Mapping_File
- The name of the URL Mapping file.
- target_directory
- The directory where the JSP files will be output.
- starting_directory
- The name of the directory containing the dynamic JSP files.
- file
- The name of a specific file to convert.
Example: perl WC_INSTALL/samples/urlmapping/bin/urlmapping.pl mapper/SEOUrlMapper.xml SiteMap test Limitations: This script does not handle JSTL or tags generated dynamically by either Java or other scripts such as out.println("<a href=\"AugInterest?aucItemId=<%=aucId%>\">")
- URL Mapping Java Application for JSTL (URLMappingConvertor)
This will convert <c:url> tag syntax such as:
<c:url var="TopCategoriesDisplayURL" value="TopCategoriesDisplay"> <c:param name="storeId" value="${WCParam.storeId}" /> <c:param name="catalogId" value="${WCParam.catalogId}" /> <c:param name="langId" value="${langId}" /> </c:url>
to
<c:url var="TopCategoriesDisplayURL" value="TopCategoriesDisplay_${WCParam.storeId}_${WCParam.catalogId}_${langId}" />
Prerequisite: Java executable is allowed to run in the command prompt window or Unix terminal Command syntax:
java com.ibm.commerce.util.URLMappingConvertor URL_Mapping_File target_directory
Parameters:
- URL_Mapping_File
- The name of the URL Mapping file.
- target_directory
- The directory where the JSP files will be output. The JSP files in all subdirectories under this target_directory will also be updated.
There is one additional parameter – the classpath needs to be specified if it's not set already. If the classpath is not set we will get ClassNotFound exceptions. For example:
java -classpath Enablement-BaseComponentsLogic.jar com.ibm.commerce.util.URLMappingConvertor URL_Mapping_File target_directory
Example:
java com.ibm.commerce.util.URLMappingConvertor WC_EAR/xml/mapper/SEOUrlMapper.xml SiteMap
Limitations:
- Any tags other than <c:param> within <c:url> will be ignored. For example:
<c:url var="ProductDisplayURL" value="ProductDisplay"> <c:param name="productId" value="${product.productID}" /> <c:param name="langId" value="${langId}" /> <c:param name="storeId" value="${WCParam.storeId}" /> <c:param name="catalogId" value="${WCParam.catalogId}" /> <c:if test="${ !empty WCParam.parent_category_rn }" > <c:param name="parent_category_rn" value="${WCParam.parent_category_rn}" /> <c:param name="view" value="imageView" /> </c:if> </c:url>
will become:
<c:url var="ProductDisplayURL" value="ProductDisplay_${product.productID}_${langId}_${WCParam.storeId}_${WCParam.catalogId}_ ${WCParam.parent_category_rn}""> <c:param name="view" value="imageView" /> </c:url>
- This script does not handle standard JSP tags or tags generated dynamically by either Java or other scripts. For example:
out.println("<a href=\"AugInterest?aucItemId=<%=aucId%>\">").
- Manually, change the dynamic URLs in JSP pages to static URLs.
- If you are using a site map, include a link to the site map starting page from the header, footer, or sidebar.
- Deploy the changed files.
Related concepts
Search engine optimization (SEO)
Related tasks
Create store pages that can be cached using cachespec.xml