GitHub Pages website connected to another domain, but I can still access via


I just configured the DNS for my domain ( to redirect to my GitHub pages site. However, I am still able to access a broken version of the site by going to which I do not want to be able to do. Any suggestions?

I have the same problem with my betting sites comparison website I’m not sure if it has something to do with the DNS configuration or with the programming code of my website. But I’m open for any solutions. Thanks!

I’ve fixed the problem, however, not how I would have liked to (without tampering with the actual website). Regardless, I’ve added a URL check which ensures the user is using the correct address within the index.js file of my React project. Even if you’re not using React, you can still place this code anywhere as long as it runs when the page initializes. I’ve included a commented version of the code below, but again, you’ll need to adapt this for your URLs and if you’re not using React.

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App';
import { BrowserRouter } from 'react-router-dom'
import registerServiceWorker from './registerServiceWorker';

//Get the window location. Even if it is at the base directory, it will still include a '/' at the end of the url.
let href = window.location.href;

//Get the base url without any forward-slashes (just in case the user was trying to navigate to other parts of the website via the url).
let location = href.substring(0, href.indexOf('/', 8));

//Define a render function so we don't have to run the same code twice.
let render = ()=>{
  ReactDOM.render(<BrowserRouter><App /></BrowserRouter>, document.getElementById('root'));

//Check if we're running locally. If we are, render the page.
if(location === "http://localhost:3000"){
  //If we're not running locally, check whether we're on the correct url, not the one.
  if(location !== ""){
    //If we're not on the correct url, redirect the user including any other routes the user was trying to navigate to e.g. '/portfolio'.
    window.location.replace(`${href.substring(href.indexOf('/', 8), href.length)}`);
    //If we're not running locally but we're on the correct url, render the page.

Hope this helps! :slight_smile:

1 Like

Hey @jackberingen, Thanks for coming back to share what worked for you!

1 Like