javascript - Good way to have multiple URLs to same site and serve slightly different content? -


take 2 websites :

website1.com  website2.com 

both owned same company, lets they're swimming pools in different towns.

both domains both point same server, website1.com. server has 1 page on it.

php , javascript available.

what client wants : if goes website1.com, top picture should of water slides. if goes website2.com, top picture should of giant turtle.

my method far :

since website2.com redirect, make redirect website1.com?source=2.

1) use javascript @ url.

2) if source in it, place cookie source=2.

3) on every page, @ cookies.

4) if there cookie source=2, variable set in javascript, poollocation=2. default value poollocation=1.

5) then, wherever content might location specific, in our top picture, use javascript test poollocation if/else.

//$(function() {... if(poollocation === 2) {     $('#variableimage1').attr('src', 'img2.png'); } else {     $('#variableimage1').attr('src', 'img1.png'); }  <img id='variableimage1' /> 

thoughts?

if both domains being allowed hit php code (there's no redirect happening in .htaccess file), recommend checking $_server['server_name'] domain , switching value of php variables (e.g. image $src variable) before code ever hits front end. approach.

just careful allow user stay on domain came in case - don't redirect them particular domain, , use relative url paths.


Comments