Onion-Location is one HTTP response header. Your clearnet site sends it, Tor Browser sees it, and a purple ".onion available" button appears in the address bar. Click it and the visitor lands on the same page at your onion address. That's the whole feature. It shipped in Tor Browser 9.5 in 2020 and it's the least painful way to move Tor users off exit relays and onto your onion service.

The header looks like this:

Onion-Location: http://youronionaddressxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.onion/path/to/page

(Swap in your real 56-character address. Every example on this page uses a placeholder.)

Why bother

When someone reads your site in Tor Browser over the clearnet, their traffic leaves the Tor network at an exit relay. The exit can see which site they're visiting and, if you somehow serve anything over plain HTTP, the content as well. Your CDN or anti-bot service may also be throwing CAPTCHAs at them, because exit IPs have a bad reputation. Move those visitors to your onion service and the exit drops out of the picture, the CAPTCHAs go away, and you've taken some load off the exit relays, which are the scarcest resource in the network.

For a news site or a privacy-focused service with a decent share of Tor readers, this is a nice thing to do for them. It's also how the big publishers advertise their onion mirrors, as we discuss in why Facebook, the BBC and the NYT run onion sites.

The rules Tor Browser applies

Tor Browser is picky about when it honours the header, and those rules exist to stop the header from becoming a phishing vector. It will only act on Onion-Location if:

  • the page was loaded over HTTPS (so nobody between the exit and your server could have injected it),
  • the value is a valid URL with an http or https scheme and a .onion host,
  • the page carrying it is not itself an onion site.

If any of those fail, the header is silently ignored. No error, no warning. That's the source of most "it doesn't work" reports: someone tests over HTTP, or puts a typo in the address, and sees nothing.

Nginx

In the HTTPS server block of the clearnet site:

server {
    listen 443 ssl;
    server_name example.com;
    # ... certificates and the rest ...

    add_header Onion-Location http://youronionaddress.onion$request_uri;
}

$request_uri keeps the path and query string, so a visitor on /blog/some-post gets sent to the same post on the onion. Watch out for Nginx's inheritance rule: if a location block has any add_header directive of its own, it does not inherit add_header lines from the server block. If your Onion-Location header mysteriously disappears on some pages, that's why. Either repeat it in those locations or put your shared headers in a small include file that every location pulls in.

Apache

With mod_headers enabled (a2enmod headers on Debian):

<VirtualHost *:443>
    ServerName example.com
    # ...
    Header set Onion-Location "http://youronionaddress.onion%{REQUEST_URI}s"
</VirtualHost>

Caddy

example.com {
    header Onion-Location http://youronionaddress.onion{uri}
    # ...
}

The meta tag alternative

If you can't change server headers (shared hosting, a static site host that doesn't let you set them), use an HTML meta tag in the <head>:

<meta http-equiv="onion-location" content="http://youronionaddress.onion/" />

Tor Browser treats this the same as the header. You'll have to set the path yourself per page if you want deep links to map correctly, which with a static site generator usually just means putting the page URL into a template variable.

Checking that it works

From any machine:

curl -sI https://example.com/ | grep -i onion-location

Then open the HTTPS site in Tor Browser and look for the ".onion available" button on the right side of the address bar. If you've set "Prioritize .onion sites" to Always (in Settings, under Privacy & Security, in the Onion Services section), Tor Browser will redirect automatically instead of showing the button, which is a good way to test the path mapping.

Mistakes that bite

The onion and clearnet sites don't serve the same paths. If your onion is a stripped-down mirror and the header sends people to /shop/cart on a site that only has a homepage, they get a 404 and decide your onion is broken. Either mirror the full site or point the header at the onion homepage only.

Sending the header from the onion itself. If the same Nginx config serves both the clearnet and the onion, the onion responses will also carry Onion-Location. Tor Browser ignores it there, so nothing breaks, but it's sloppy and it's one more place where the clearnet and onion configs are entangled. If you're running the onion partly to protect the server's location, that entanglement is a bad sign in itself; see how onion services leak their real IP.

Using a wrong or stale address. Onion-Location is a signal of trust: you are vouching for that address, over HTTPS, on your own domain. That's actually one of the best ways for users to verify an onion address (we list it in How to Verify an Onion Address). So if you rotate your onion keys, update the header the same day.

Forgetting about HTTPS on the onion. If your onion serves HTTP only and the header points to https://, visitors hit a connection error. Match the scheme to what the onion actually serves. Plain http:// is fine and normal; the reasons you might want a certificate anyway are covered in HTTPS on .onion.

The header itself is documented on the Tor Project's community site, at community.torproject.org/onion-services/advanced/onion-location, which is worth a look if you hit an edge case not covered here. The glossary entry is the two-sentence version.

#onion-location #http-headers #tor-browser #nginx #apache