3

I have a sitemap.xml in file in /public folder and I want to make it public so that Google can read it from www.my_domain.com/sitemap.xml. How do I do that?

EDIT I have taken over the project and this kind of setup is not known to me. This is what I have now.

// Set up the router, wrapping all Routes in the App component
import App from 'containers/App';
import createRoutes, { createIndexRoute } from './routes';

const rootRoute = {
  path: '/(en)(pl)(de)(bg)(cz)(ee)(gr)(hr)(hu)(it)(lt)(lv)(ro)(si)(sk)',
  component: App,
  childRoutes: createRoutes(store),
  indexRoute: createIndexRoute(store),
};

const render = (translatedMessages) => {
  ReactDOM.render(
    <Provider store={store}>
      <LanguageProvider messages={translatedMessages}>
        <Router
          history={history}
          routes={rootRoute}
          render={applyRouterMiddleware(
            useScroll(
              (prevRouterProps, { location }) =>
                prevRouterProps && location.pathname !== prevRouterProps.location.pathname
            )
          )}
        />
      </LanguageProvider>
    </Provider>,
    document.getElementById('app')
  );
};

Each route looks like this

###routes.js
export default function createRoutes(store) {
  // Create reusable async injectors using getAsyncInjectors factory
  const { injectReducer, injectSagas } = getAsyncInjectors(store);

  return [
    {
      path: '/home',
      name: 'home',
      getComponent(nextState, cb) {
        const importModules = Promise.all([
          System.import('containers/HomePage/reducer'),
          System.import('containers/HomePage/sagas'),
          System.import('containers/HomePage'),
        ]);

        const renderRoute = loadModule(cb);

        importModules.then(([reducer, sagas, component]) => {
          injectReducer('home', reducer.default);
          injectSagas(sagas.default);

          renderRoute(component);
        });

        importModules.catch(errorLoading);
      },
    }
  ]
}

I just want a single route to /sitemap.xml

jedi
  • 2,003
  • 5
  • 28
  • 66
  • Make sure your `public` folder is deployed at the root of the app? – Dave Newton Nov 04 '19 at 14:00
  • 1
    But when I try to access it locally I am getting a blank page and an error in the console `Warning: [react-router] Location "/sitemap.xml" did not match any routes` – jedi Nov 04 '19 at 14:01
  • You'd probably need to add actionable information to the question, then, like how everything is being routed, etc. – Dave Newton Nov 04 '19 at 14:03

1 Answers1

3

I resolved by adding xml to my server rewrite rule.

It was </^((?!\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>

Updated to </^((?!\.(css|gif|ico|jpg|js|png|txt|svg|woff|xml|ttf)$).)*$/>

When I visited the /sitemap.xml I could now see the sitemap where before it was showing the page not found route.

Dylan w
  • 2,565
  • 1
  • 18
  • 30