Hi @SR VSP ,
You can add a script editor web part or content editor web part to add the javascript to the page.
Open a notepad and paste the below code and save it.
<script "text/javascript">//<![CDATA[alert("You will be redirected automatically in 10 seconds!!!");//]]></script><meta http-equiv="refresh" content="10;url="https://xxx.sharepoint.com/sites/xxx">
In the next step upload the text file to a SharePoint document library and copy the path of the file. Next, edit the web part page and click on Add web part. From the Ribbon click on Insert -> Add web part. From the list of web parts, Select Media and Content category Select Content Editor, and click on Add.
After that edit the web part and give the SharePoint library link of the notepad file that we saved above in the Content Link of the web part properties window. Then click on OK as shown in the figure below.
Now Save and close the page. Now, whenever a user opens the SharePoint On-Premise site, it will redirect to the specified SharePoint Online URL.
Reference: SharePoint redirect to another page.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.