迁移旧网站时PHP header跳转失效,请求解析路径中/s与/r的作用
/s/ and /r/ in Your Redirect Path Hey Bruce, great question—those /s/ and /r/ bits aren’t standard PHP or HTTP default behavior, they’re definitely tied to how your friend’s old server or website was configured. Let’s break down the most likely reasons they existed:
Common Explanations for /s/ and /r/
URL Rewrite Rules (Mod_Rewrite/Nginx)
It’s super common for old sites to use rewrite rules to mask real file paths. For example:/s/might have been a virtual prefix mapped to the actual root directory of your friend’s site via Apache’s.htaccessor Nginx config. So when the old server saw/s/subdir/..., it actually served files from something like/var/www/real-site-files/subdir/..../r/could be a route prefix for a custom routing system. Maybe the old site used a lightweight framework or custom code where all requests starting with/r/got sent to a router script (likesubdir/router.php) that handled theindex/part as a page action, instead of pointing directly to a physicalindex.phpfile.
Server Aliases/Virtual Directories
On the old server,/s/might have been set up as an alias (Apache’sAliasdirective or Nginx’saliasblock) pointing to a non-web-root directory. So/s/subdir/wasn’t a physical folder in the server’s web root—it was a shortcut to a different location entirely.Multi-Site or Prefix-Based Deployment
If the old server hosted multiple sites,/s/could have been a site identifier (like "site" or "store") to separate your friend’s site from others./r/might have stood for "route" or "request" as part of the site’s internal structure to handle dynamic page loads.
Next Steps to Fix the Redirect
To get this working on the new server, you have two options:
- Replicate the Old Server’s Config
Dig into the old server’s configuration files (.htaccessfor Apache, site-specific Nginx configs) to find the rules that handle/s/and/r/, then copy those rules over to the new server. - Adjust the Redirect Path
If you don’t need the old prefixes, update the header redirect to point directly to the physical file path, like theheader("Location: /subdir/index.php")you mentioned—just make sure that path matches where the actualindex.phplives on the new server.
Also, check the old site’s directory structure: if there’s no physical /s/ or /r/ folder, that confirms it’s a rewrite/alias setup rather than a real file path.
内容的提问来源于stack exchange,提问作者Bruce

