Strip HTML extension from outgoing URL

1.8k Views Asked by At

I am using AEM. I have configured some vanity URL's with redirect. Ex:

/coaties > /content/geometrixx-outdoors/women/coats/winter-coat.html

Also in the web server, I have made configuration to strip HTML extension so my web-server removes the html extension with another redirect. Now when I hit vanity URL, I will have 2 redirects

/coaties > /content/geometrixx-outdoors/women/coats/winter-coat.html [1st redirect]
/content/geometrixx-outdoors/women/coats/winter-coat.html > 
/content/geometrixx-outdoors/women/coats/winter-coat [2nd redirect]

I want to avoid 2 redirects and I dont want to show HTML extension to end users.

/coaties > /content/geometrixx-outdoors/women/coats/winter-coat [only one redirect]

I spent some time on the Sling side with no luck. All I understand is, since Sling will return 403 for all URL's without extension, it always returns URLs with extension. Is this possible at dispatcher or web server side ?

2

There are 2 best solutions below

0
On

If i understand, you want to strip the .html extension from all the pages of your site.

The solution of @awd will ensure that all the hrefs in your page would be transformed to uris with no extension.

If you want no extension at all in your site, you should use an internal redirect by creating map under /etc/maps, you can find the official documentation here: http://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html

0
On

Thanks everyone for contributing.

I found the following solution for the problem

I would do the following configurations for webserver For apache, in httpd.conf

Header edit Location (.*).html$ $1

For iPlanet in obj.conf

<If $srvhdrs{'Location'} =~ "^(.*).html$">
   Output fn="set-variable" $srvhdrs{'Location'}="$1"
</If>

This would make sure that html extension would be removed from location header for redirected URL's.