0

I have 2 sites. We will call them site1.com and site2.com

When a user visits site1.com I would like it to redirect them to site2.com. Easy to do

However, if a person was to visit site1.com/# I would like that to redirect them to site2.com and whatever # they put will be added to the body tags of site2.com as a class. so if they were to go to site1.com/6 <body class="6"> for example. Basically taking the path of the first site and adding that as a class on the body tag of site 2. Can someone point me in the right direction on how to achieve this

  • For ideas, see [How to get Url Hash (#) from server side](https://stackoverflow.com/a/1586300/924299). – showdev Jun 06 '21 at 04:12

2 Answers2

0

This will require collaboration between both domains.if done with JavaScript, not sure about PHP

On site1.com, redirect to a new path with the pathname like so (this is assuming of course, that the page will be shown to all locations matching site1.com/*):

location = "http://site2.com/"+location.pathname

On site2.com, receive this, then use classList.addClass(name) to document.body like so:

document.body.classList.add(location.pathname);
Spectric
  • 30,714
  • 6
  • 20
  • 43
0

If you are using php you can get the url path info with $info = $_SERVER['PATH_INFO']; if the URL is 'site1.com/5' the result would be '/5'. After that you can redirect the user with header('Location: site2.com'.$info);

noah1400
  • 1,282
  • 1
  • 4
  • 15