URL Rewriting and Anonymous Access with SharePoint – Part Five

23 Mar

Other Exceptions – Search and XSLT with Rewriting

There are some cases where the link will still be the full URL, if a user sets a link to “http://geeksinsuits.com/ca/pages/default.aspx” only the URL will be overwritten, not the actual text itself. So users need to name hyperlinks appropriately in a way that represents where the link is going, and not set the link text to the URL itself. An example of this would be using “About us” instead of “http://geeksinsuits.com/ca/pages/aboutus.aspx

In some cases this is unavoidable such as for search results. The XSLT will be using the actual page URL as the link text. The easiest way to get around this is by adding some JavaScript.

This post assumes that there is a search service application set up, the server standard site features have been enabled and there is a search page that is bringing back page results.

Search Core Results and Rewriting

There are a couple of tricks with search that might need to be configured. Firstly if your anonymous users cannot see search results (nothing shows up) and you can when your logged in you might not have set the right permissions on the extended site.

  1. Go to IIS
  2. Go to Geeks In Suits Public (or your extended internet site)
  3. Double click on Authentication
  4. Right click Anonymous Authentication and click Edit
  5. If the radio button has Specific User selected change it to Application pool identity. This got me earlier…

Secondly if you are using a search core results web part and are getting a 404 error when searching the page you may have to change the scopes drop down mode.

Edit the Search Box web part and set the Scopes Dropdown to “Do not show scopes dropdown, and default to target results page”. If this isn’t set an extra query string will be added onto the URL like below, this will result in a 404 error.



Most XSLT templates will show hyperlinks where the text is the URL. What we need to do to get around this is change the link on the client side as IIS cant change this content for us. We will step through making some changes to the standard search core results xslt. The same changes can apply to any XSLT however, you just need to add some JavaScript and call it via a template.

  1. The standard search XSLT shows the link text at the bottom of each result like below. We want this URL to look like the address bar in the browser
  2. Edit the Search Core Results web part
  3. Edit the XSLT by clicking on XSL Editor under Display Properties. If you cant do this untick User Location Visualisation.
  4. If you have another text editor i suggest copying this out to there for editing
  5. Find <xsl:template match=”Result”> (should be line 206)
  6. After the end of this template (line 415) add the below template and javascript. We will be able to call this template from anywhere in the XSLT<xsl:template name=”ReWriteURL”><xsl:param name=”currentId” /><script type=”text/javascript”>


    var id = ‘<xsl:value-of select=”$currentId” />’;


    // javascript for replacing hyperlinks innertext to friendly urls, but only based on the url

    // that has already been set, so it doesnt matter if it has been re-written or not

    function UpdateFriendlyURLS(id)


    var obj = document.getElementById(id);

    if (obj != null)


    obj.innerHTML = obj.href;






  7. Now we need to call the template after the result has been read out. Just before the result template ends add the template call for the javascript (just before line 415), this will pass in the ID of the current result link and change the URL text.<xsl:call-template name=”ReWriteURL”><xsl:with-param name=”currentId” select=”concat($currentId,’_URLlink’)”/></xsl:call-template>
  8. Now all we need is a hyperlink that has the right ID for our JavaScript to grab and change. In the standard Search Core Results XSLT there are two places, line 274 and line 389.
  9. Delete the <xsl:choose> node so there is only an empty span
  10. Replace both instances of this code with the following<a href=”{$url}” id=”{concat($currentId,’_URLlink’)}”> <xsl:value-of select=”url”/> </a>
  11. If you had edited the code elsewhere copy this back into the XSL Editor on the web part, press save
  12. OK on the web part properties window
  13. Save and publish the page
  14. Now go to the page anonymously via the internet extended site, the URL text will be re-written like the rest of the page

Cool, what now? Next Post… (Summary yay!)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: