◉RORK LABJP
●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens
Articles/App Dev
◇ App Dev/2026-10-16Intermediate

301 or Internal Rewrite for Wallpaper Resolution Routing? Inside One Host, I Chose the Route That Doesn't Change the URL

When one host picks an image resolution for you, should it answer with a 301 or rewrite internally? I ran both on nginx and compared round trips, rule-order traps, and a small verification script.

image deliverynginx301 redirectinternal rewritecaching4

✦ Premium Article

I was tidying image delivery for a wallpaper app. The app asks for an image like sunset.jpg?w=640, adding the width it wants. On the server there are folders split by width. The glue between the two is a routing rule, and I stalled on one question: write it as a 301, or as an internal rewrite?

Both serve the image. That is exactly why it is easy to pick one without saying why. Here is the conclusion first: when the routing stays inside one host and the caller has no need to know about it, keep the URL unchanged. What follows is the same decision reproduced on a local nginx, with both versions actually run.

What needs routing

Here is the setup on one page.

URL requestedFile to return
/img/sunset.jpg?w=640/img/w640/sunset.jpg
/img/sunset.jpg?w=1280/img/w1280/sunset.jpg
/img/sunset.jpg (no value, or an unexpected one)/img/sunset.jpg (the original)

For the test I placed dummy files of 2,000 bytes (640 wide), 8,000 bytes (1280 wide), and 30,000 bytes (the original). Different sizes tell you at a glance which file came back.

The 301 version

This is the first thing most of us write.

# A: route with a 301
map $arg_w $res { default ""; "640" "w640"; "1280" "w1280"; }
 
location ~ ^/a/img/(?<f>.+)$ {
  if ($res = "") { return 301 /img/$f; }
  return 301 /img/$res/$f;
}

Here is what curl shows.

$ curl -si "http://127.0.0.1:8081/a/img/sunset.jpg?w=1280" | sed -n '1p;/^Location/p'
HTTP/1.1 301 Moved Permanently
Location: http://127.0.0.1:8081/img/w1280/sunset.jpg

Following the redirect gives num_redirects of 1, so fetching one image costs two round trips, and the access log grows two lines per image. After 300 calls the log held exactly 303 lines with a 301 status (the extra three are my manual checks).

There is a second point that is easy to miss. In the HTTP specification (see the 301 entry in RFC 9110), a 301 is cacheable by default. Browsers remember "this URL moved there," and a corrected rule may not reach a client that already remembered the old answer. That is why you verify in a private window. This part is a reading of the spec; I did not measure how long any given browser keeps it.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦You can tell with a single curl whether your image delivery changes the URL or keeps it
✦You can take home a resolution router built from map and rewrite, with no if, that falls back to the original for unexpected values
✦You can avoid shipping a 301 that browsers and CDNs remember and that you can no longer fix
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

◇ App Dev2026-10-29
An Image Requested Once Before Its Upload Stayed a 404 at the Edge. I Split the Retention Rules by Status Code and Made Upload and Purge a Single Step
A new wallpaper stayed missing in some regions because the CDN kept a 404, fetched once before the upload, as long as it kept the image itself. Per-status retention, a two-request diagnosis, and pairing upload with purge, tested in Node.
◇ App Dev2026-11-24
Why Only the First Page of Your Carousel Is Blank at Launch, and How to Make FlatList Start on the Right Page
My wallpaper app opened on an empty first page. Swiping showed page two just fine, and swiping back left page one empty again. The pager had been told where to start before it knew its own size. Here is the Android fix and the Expo FlatList pattern that closes the same gap.
◇ App Dev2026-11-16
I Set cameraPermission to false for a Photo Picker, and the QR Scanner Lost Its Camera Too
In expo-image-picker, cameraPermission: false deletes NSCameraUsageDescription from Info.plist on iOS and blocks CAMERA for every package on Android. Here is what happens when you also use expo-camera, and a working script that checks permissions before you submit.