Search code examples
djangoserverstaticjekyllnetlify

Static site with netlify + Django on the same url


Let's assume I own the domain:

foobar.com/

I want to use Netlify for my static pages like

foobar.com/features/
foobar.com/pricing/
foobar.com/imprint/
etc.

But I also have a Django application on a seperate server on AWS that has nothing to do with the static sites served by Netlify.

My Django has urls like

foobar.com/login/
foobar.com/dashboard/
etc.

Is it possible to use Netlify for a few static pages and my Django application for other pages? I don't know how start or if this is event possible.


Solution

  • It will depend on how your Django apps handle the target, but you could use rewrites on Netlify using the HTTP status code 200 with a redirect rule (rewrite).

    If the API supports standard HTTP caching mechanisms like Etags or Last-Modified headers, the responses will even get cached by CDN nodes.

    Have DNS set foobar.com to the Netlify site.

    Decide the domain for the Django site on AWS. (proxy.foobar.com)

    Setup _redirects at the root of the Netlify site to use Proxy (rewrites) on Netlify

    /login/*       https://proxy.foobar.com/login/:splat  200
    /dashboard/*   https://proxy.foobar.com/dashboard/:splat  200
    

    Note: This is how you can incrementally switch a site over to Netlify without having to refactor a site all at once.