Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
The reliable NGINX pattern for a domain move is a dedicated redirect-only server block for the old hostname. Use return 301 https://new.example.com$request_uri; so every request reaches the new host with its original path and query string intact. Keep the destination website in a separate HTTPS server block, test the configuration before reloading, and use temporary redirects while you validate a migration.
The basic domain redirect pattern
NGINX chooses a virtual server by matching the request hostname against server_name. For an unconditional move from one hostname to another, the clearest design is one small server block that does nothing except issue the redirect. NGINX’s rewrite-conversion guidance describes this as defining a separate server for the old name.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchserver {
listen 80;
server_name old.example.com;
return 301 https://new.example.com$request_uri;
}
A request for http://old.example.com/docs/setup?edition=2 receives a permanent response whose Location header is https://new.example.com/docs/setup?edition=2. The redirect block does not proxy content, run application code, or need a location section. That separation makes the mapping easier to audit and prevents old-domain logic from leaking into the new site.
Why return is the right first choice
Use return when every request handled by a server or location goes to one destination assembled from variables such as $request_uri. The directive is valid in both server and location contexts. It expresses the outcome directly and avoids regular-expression matching and conditional flow.
#1 Best Overall
- Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
- With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
- Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
- Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
- Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
Use rewrite when the destination depends on a pattern or when different source paths need different transformations. A path-by-path rewrite can be appropriate after a site restructure, but it is unnecessary complexity for a hostname-only migration. NGINX supports redirect responses such as 301, 302, 303, and 307 with return; select the status that matches the operational intent rather than adding a rewrite rule merely because it is familiar.
Build the destination HTTPS server separately
The new hostname needs its own serving configuration. A redirect to HTTPS does not create TLS; the destination must listen on port 443 and present a certificate covering the hostname in the request.
Recommended Free Tools
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/nginx/ssl/www.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
# application locations...
}
server {
listen 80;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
Protect the private key while keeping it readable by the NGINX master process, as required for the TLS listener. Verify that the certificate names include every destination hostname clients will use, including an apex name or www name when both are intended to work. If the certificate or Server Name Indication configuration does not cover the destination, users can see a TLS warning after following an otherwise correct redirect.
For a redirect that starts on HTTPS, certificate validation occurs before NGINX can send any HTTP response. Consequently, the old HTTPS name also needs a certificate that covers it, even if that server block serves no content and immediately returns a redirect. This is a frequent reason an apparently correct migration fails only for https://old.example.com.
Canonical hostname configurations
Choose one canonical public hostname and make every alternate form point to it. Put only the source name in each redirect block; put the canonical name in the content-serving block. This prevents the destination from matching its own redirect and creating a loop.
Apex to www
server {
listen 80;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/nginx/ssl/www.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
# application locations...
}
www to apex
server {
listen 80;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
# application locations...
}
Old domain to a new domain
For a complete domain migration, create redirect listeners for every scheme and old hostname that clients may still request, then serve the new hostname independently.
server {
listen 80;
server_name old.example.com old.example.net;
return 301 https://new.example.com$request_uri;
}
server {
listen 443 ssl;
server_name old.example.com old.example.net;
ssl_certificate /etc/nginx/ssl/old.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/old.example.com.key;
return 301 https://new.example.com$request_uri;
}
server {
listen 443 ssl;
server_name new.example.com;
ssl_certificate /etc/nginx/ssl/new.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/new.example.com.key;
# application locations...
}
The old HTTPS block needs a valid certificate because the TLS handshake happens before NGINX can send the redirect. Without a certificate that covers the old HTTPS hostname, a browser may stop with a certificate error and never receive the redirect.
Rank #2
- Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
- Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
- Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
- Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
- Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
Force HTTP to HTTPS without changing the host
If the canonical hostname is already correct and only the scheme must change, use a port-80 block that names the accepted hosts and redirects to the chosen HTTPS host.
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
Configure the HTTPS endpoint separately with listen 443 ssl, ssl_certificate, and ssl_certificate_key. Listing both names on port 80 is useful when both forms should converge on one HTTPS hostname. If you want to preserve the incoming host instead, a documented NGINX deployment pattern uses https://$server_name$request_uri; choose that only when each accepted name has an intentional HTTPS destination and matching certificate.
Decide whether host canonicalization and HTTPS enforcement should happen in one hop. Sending http://example.com directly to https://www.example.com avoids a separate HTTP-to-HTTPS hop followed by an apex-to-www hop. Whatever policy you choose, make the expected final URL explicit and verify the complete chain with a client rather than assuming the browser performed only one redirect.
Free tools Windows power users keep installed
One-click scans. No signup required.
Preserve paths and query strings correctly
$request_uri contains the original path and query string. It is the variable to use when the old and new sites have the same URL structure.
return 301 https://new.example.com$request_uri;
With that line, /docs/setup?edition=2 remains /docs/setup?edition=2 at the new host. This matters for bookmarks, search results, shared links, downloads, and tracking parameters. Replacing the variable with a literal slash intentionally collapses every source URL to the homepage and should be done only when that is the migration plan.
Do not append a second question mark or manually reconstruct arguments unless you have a specific transformation. Hand-built query strings can duplicate parameters or discard values that were present on the original request. Test a URL with no query string and another with several parameters so both forms behave as intended. Include a nested path, not just the home page, because a root-only test cannot reveal a missing URI variable.
Understand server_name matching
NGINX supports exact names, wildcard names, and regular-expression names. Its documented matching priorities determine which virtual server receives a request. Exact names are generally the safest choice for a canonical-domain redirect because the scope is obvious and limited.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #3
- 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
- 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
- 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
- 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
- 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
| Hostname declaration | Best use | Main risk |
|---|---|---|
Exact name, such as old.example.com |
A known domain or subdomain migration | Every required alias must be listed explicitly |
Wildcard, such as *.old.example.com |
A controlled family of subdomains that all share one destination policy | Unintentionally redirects unrelated subdomains |
| Regular expression | Specialized, pattern-based hostname handling | More difficult review and higher risk of an unintended match |
A broad wildcard is not a shortcut for a multi-tenant environment. Use it only when every matched subdomain is intentionally sent to the same destination. Check for duplicate declarations in other included files, because a typo or competing block can make a different virtual server win.
Remember that the request’s host and listening address both matter. A block written correctly for port 80 does not automatically handle the same hostname on port 443. Define the required listener and name combination explicitly, then test each scheme. Also test an unknown Host value: it may be handled by the default server rather than by any named redirect block.
Choose the right redirect status
| Status | Use it when | Operational implication |
|---|---|---|
301 |
The domain or canonical-host change is permanent | Browsers and intermediaries may cache it, making rollback less immediate |
302 |
The redirect is temporary or you are testing behavior | Clients are less likely to treat the mapping as permanent |
307 |
A temporary redirect must preserve the HTTP method and request body | Useful for method-sensitive testing or temporary routing |
A domain migration normally ends with 301. During a first rollout, a temporary status on a controlled hostname lets you inspect behavior before browsers and intermediaries retain a permanent mapping. Test the response itself—status code and Location header—not merely what a browser displays. A browser may hide an earlier redirect from casual inspection, while the response headers show exactly which server answered and where it sent the client.
Use a 301 only after the source names, destination certificate, URI mapping, and fallback behavior have been checked. Reverting the configuration changes what new requests receive, but it cannot instantly remove every cached permanent response. Keeping the temporary and permanent configurations visibly distinct also makes a later review safer.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Safe deployment procedure
- Back up the active configuration. Save the main file and any included virtual-host files so you can compare or restore the previous state.
- List the exact source names. Include every old apex,
wwwalias, and legacy domain that should redirect. Do not add a wildcard unless its full scope is intentional. - Add redirect-only blocks. Place the old HTTP and, when needed, old HTTPS names in blocks that return the target URL with
$request_uri. - Verify the destination TLS setup. Confirm the 443 server has a certificate covering the destination hostname and that the key permissions allow the NGINX master process to read the key.
- Validate syntax. Run
nginx -ton the host before reloading. A successful test checks configuration syntax and referenced files without changing live traffic. - Reload through the normal service manager. Use the reload procedure for your operating system or distribution so existing connections can finish while the new configuration is adopted.
- Probe representative URLs. Check both HTTP and HTTPS, apex and
www, a nested path, a URL with a query string, and an unknown host header. - Inspect every hop. Record the status,
Locationvalue, and number of redirects with a client such ascurl -I. A normal migration should reach the final HTTPS URL without a cycle.
Example verification commands
curl -I http://old.example.com/docs/setup?edition=2
curl -I https://old.example.com/docs/setup?edition=2
curl -I http://example.com/docs/setup?edition=2
curl -I https://www.example.com/docs/setup?edition=2
In a shell, quote URLs containing special characters when necessary. Compare the returned Location header with the expected host, path, and query. Follow redirects separately with a command such as curl -IL when you need to count the complete chain. Run the checks against both a known URL and the root path; a configuration can preserve one while mishandling the other if an additional location rule is present.
Diagnose common failures
Redirect loop
A loop usually means the destination hostname is also covered by a redirect block, or another layer is forcing HTTPS while NGINX constructs a URL with the wrong scheme. Inspect each hop with curl -IL, then compare the requested host and scheme with the matching server_name block. If a load balancer or proxy sits in front of NGINX, make sure its HTTPS policy and the origin’s scheme handling agree instead of repeatedly upgrading the same request.
Path or query string disappears
Check the return target for $request_uri. A target ending only in a slash intentionally sends every source URL to the root. Restore the variable when the new site keeps the old URL structure.
Rank #4
- 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
- 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
- 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
- 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
- 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
The wrong virtual server responds
Look for misspelled names, duplicate server_name entries, an unexpected wildcard, or a default listener on the same address and port. NGINX’s hostname matching rules decide which block wins; the file order is not a substitute for a correct name declaration. Test with the exact host and scheme that a client sends.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
TLS warning after the redirect
For an HTTPS source, the certificate must be accepted before NGINX can return the redirect. For the destination, the 443 block must present a certificate whose names cover the target host. Check both certificates and the SNI-selected virtual server rather than troubleshooting only the redirect line.
Unknown hosts are captured unexpectedly
A default server can receive requests whose Host header matches no intended name. Keep a deliberate default policy and test it independently. Do not let an accidental default block redirect arbitrary hostnames to your production domain.
Premature 301 caching
Permanent redirects can be cached by browsers and intermediary systems. Before committing a 301 on a public hostname, test with 302 or 307 on a controlled name, or use a clean client that has not retained the earlier response. Once a 301 has been distributed, changing NGINX does not instantly erase every cached result.
Redirect works for HTTP but not HTTPS
Check whether a 443 block exists for the old name and whether its certificate covers that name. Port-80 success says nothing about the TLS handshake on port 443. If the handshake fails, the request never reaches the return directive, so adding another HTTP rule will not solve the problem.
Design decisions for a reliable migration
- Scope: exact hostnames are easier to reason about than broad patterns.
- Destination: keep the content-serving HTTPS block separate from redirect-only blocks.
- URI behavior: use
$request_uriwhen paths and arguments map unchanged; write explicit path rules only for a planned restructure. - Status: use temporary codes during validation and 301 for a confirmed permanent change.
- TLS: provision certificates for every HTTPS hostname that must answer, including old names that need to issue a redirect.
- Reversibility: retain a configuration backup and record the expected redirect chain before deployment.
- Chain length: map each old form directly to the final canonical HTTPS URL where practical, rather than relying on several sequential canonicalization hops.
- Fallback behavior: define and test what happens to unmatched hostnames instead of inheriting an accidental default response.
Practical checklist
- Old hostnames are listed explicitly in the redirect blocks.
- The destination hostname is not included in those same redirect blocks.
- Each permanent target uses
return 301and the correct absolute HTTPS URL. $request_uriis present when the original path and query must survive.- The destination has a separate
listen 443 sslserver with valid certificate directives. - Old HTTPS names have certificates if they must redirect from HTTPS.
nginx -tsucceeds before reload.- Tests cover both schemes, both canonical aliases, nested paths, query strings, redirect count, and unknown hosts.
Frequently Asked Questions
How do I redirect an old domain to a new domain in NGINX?
Create a dedicated redirect-only server block for the old hostname and return the final HTTPS URL with $request_uri: return 301 https://new.example.com$request_uri;. Keep the new hostname in its own serving block.
How do I redirect www to non-www, or non-www to www?
List only the noncanonical hostname in a port-80 redirect block and send it to the chosen canonical HTTPS hostname. The canonical name belongs in the separate 443 content-serving block, so it cannot redirect to itself.
Best Value
- 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
- 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
- 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
- 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
- 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
How do I force HTTP to HTTPS?
Use a port-80 block listing the accepted hostnames and return an absolute https:// URL. Configure the destination separately with listen 443 ssl, ssl_certificate, and ssl_certificate_key.
Will the redirect keep the original path and query string?
Yes, when the target ends with $request_uri. For example, /docs/setup?edition=2 is sent to the same path and query on the new host.
Why does an HTTPS redirect show a certificate warning first?
TLS negotiation happens before NGINX can return the redirect. The old HTTPS hostname therefore needs a certificate covering that name, and the destination needs a certificate covering its own hostname.
Should I use rewrite instead of return?
Use return for an unconditional hostname mapping. Use rewrite only when a pattern-based or conditional URI transformation is actually required.
Should I test with 301 immediately?
Use 302 or 307 while validating a public migration or controlled hostname, then switch to 301 after checking hosts, paths, queries, TLS, and redirect count. Permanent responses may be cached.
How can I investigate a redirect loop?
Run curl -IL and inspect every status and Location header. Confirm that the destination is not matched by the old redirect block and that any proxy’s HTTPS policy agrees with NGINX.
The Bottom Line
For a straightforward NGINX domain move, define an exact, redirect-only server block for each old hostname and use return 301 https://canonical-host$request_uri;. Configure the destination’s 443 TLS server separately, provide certificates for old HTTPS names that must redirect, test with temporary status codes and curl, run nginx -t, then reload. Exact host matching, preserved URIs, deliberate default-server behavior, and a checked certificate chain prevent the loops, lost URLs, and TLS errors that make domain migrations fail.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

