Forum Discussion

snaffle's avatar
snaffle
Expert
6 years ago

Page Initialization CNAME Redirect for SEO

Hi there,

We currently have our main community CNAME set to https://domain.com but the CNAME for https://www.domain.com is also enabled, though not actively promoted.

So as to just have the one domain collecting stats in Google Analytics etc I'd like to have a proper wildcard redirect on the domain so that url requests to https://www.domain.com redirect to the non-www equivalent but also retain the url and parameters.

But without a htaccess file I can't quite work out how to do this.

I've managed in my Page Initialization script to do a general redirect with:

<#if http.request.serverName == "<a href="http://www.domain.com" target="_blank">www.domain.com</a>">
	${http.response.setRedirectUrl("<a href="https://domain.com" target="_blank">https://domain.com</a>")}
</#if>	

 

But this of courses strips out the url/parameters and just sends all urls back to the community page.

I tried the following in the Page Initialization script hoping I could just substitute it  but it didn't work:

<#assign hostName = http.request.serverName />
<#if hostName == "<a href="http://www.domain.com" target="_blank">www.domain.com</a>">
	<#assign hostName = "domain.com" />
</#if>	


Does anybody have any suggestions as to how I might be able to achieve this in the Page Initialization script?

Thanks

Nathan

    • snaffle's avatar
      snaffle
      Expert

      Thanks Parshant,

      That's a shame, thought I could wrangle it myself.

      But thanks for the direction, I'll follow it up with support.

      Nathan