Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides 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

NGINX does not read Apache .htaccess files. When a site is moved from Apache, its RewriteRule and RewriteCond directives remain inactive unless you translate their behavior into the NGINX server and location configuration. Without an application fallback, NGINX checks the configured document root for a matching file or directory and returns 404 for a pretty URL that exists only inside your application.

The usual front-controller fix is try_files $uri $uri/ /index.php?$args;, but that line is correct only when the active root, PHP handler, virtual host, and application entry point match your deployment. The guide below shows how to convert the intent safely and how to find the cause when a translation still returns 404.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why an Apache rewrite works there but returns 404 on NGINX

Apache evaluates .htaccess files in the directory that contains them, applying their rules to requests handled by that directory. NGINX has no equivalent per-directory file that it discovers automatically. Copying an Apache .htaccess file into the web root therefore changes nothing: directives such as RewriteEngine On, RewriteCond, and RewriteRule are never parsed by NGINX.

For a request such as /products/red-shoes, NGINX selects a server block and then a location. It maps the URI to the active root or alias and checks the filesystem. If there is no real file or directory at that path, and no rule sends the request to your application, NGINX ends the request with 404. The homepage can still work because / may resolve to an actual index.html or be handled by a separate index directive, while every application route misses the filesystem lookup.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

The repair is not to make NGINX interpret Apache syntax. Put equivalent behavior in the loaded NGINX configuration, then validate and reload that configuration. The correct directive depends on the original intent: an external redirect, a regular-expression URI transformation, a file-existence test, or a handoff to an application server.

Identify the NGINX configuration that is actually serving the request

Editing the wrong file or virtual host produces the same symptoms as a missing rule. Establish which binary, configuration path, host, and location handle the failing URI before changing rewrite logic.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Check the installed binary and build options with nginx -v and nginx -V. The latter displays the compiled default configuration path and enabled options.
  2. Find the service’s loaded configuration path. Distribution packages commonly use a main file that includes files from a directory such as conf.d or sites-enabled, but the exact layout varies. Use the path shown by your service or package rather than assuming a filename.
  3. Open the server block whose server_name matches the hostname in the failing request. A default virtual host can answer the request if the intended host is absent, misspelled, or not enabled.
  4. Within that block, locate the location that matches the URI. A regular-expression location for PHP, an exact location, or a longer prefix can bypass a general location / containing try_files.
  5. Confirm the root or alias used by that location. A deployment that changed from a project directory to a public directory can leave NGINX looking in the wrong place even when the files exist elsewhere.

Do not rely on the presence of a file on disk alone. The file must be under the root selected for this request, and the selected location must contain an appropriate handler for the final URI.

The standard front-controller translation

Most PHP frameworks and many custom applications have one entry point that receives routes which are not real files. The common NGINX shape is:

server {
    root /var/www/example/public;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .php$ {
        # Add the PHP-FPM settings required by this deployment.
    }
}

This is a pattern, not a universal copy-and-paste server block. Replace the path and fallback with the values used by your application, and supply a working PHP-FPM or other upstream handler where required.

What each try_files argument does

  • $uri tests the requested URI as a file beneath the active root or alias. A request for /css/site.css can therefore be served directly when that file exists.
  • $uri/ tests the URI as a directory. This permits directory handling, including an index file or a separate location, when a real directory exists.
  • /index.php?$args is the final fallback. If neither candidate exists, NGINX internally redirects the request to the application entry point while preserving the original query arguments.

The final parameter is an internal redirect, not a browser-visible 301 or 302. The browser continues to display the original pretty URL, while the application receives the fallback URI. The fallback must exist under the configured root and match a handler; otherwise the rewrite appears to work but the next phase returns 404 or another upstream error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Static-site variant

A site with no application server usually should not send unknown paths to PHP or a proxy. Use an explicit failure or a static fallback that exists:

location / {
    try_files $uri $uri/ =404;
}

For a single-page application, the intentional fallback may instead be a real HTML entry point:

location / {
    try_files $uri $uri/ /index.html;
}

Choose the final target based on how the site is built. Sending requests to a nonexistent fallback merely moves the 404 one step later.

Reverse-proxied application variant

An application listening on an upstream socket or port needs a proxy fallback rather than a PHP file. One common structure is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
location / {
    try_files $uri $uri/ @app;
}

location @app {
    proxy_pass http://127.0.0.1:3000;
}

The upstream address, headers, timeout settings, and URI behavior are deployment-specific. The important distinction is that try_files handles local static assets first, then sends non-file requests to a named application location.

Choose the NGINX directive that matches the original intent

Original intent Preferred NGINX tool Processing result Typical failure to check
Send a client to a new, fixed URL return External redirect or explicit status Wrong status code or malformed target
Transform a URI with a regular expression rewrite URI change, optionally followed by a new location search Rule order, loops, or lost query arguments
Serve an existing file or directory, otherwise continue try_files Local file serving or internal fallback Wrong root, alias, or final URI
Pass an application request to a process proxy_pass, FastCGI, or a named location Upstream application handling No matching upstream handler

Use return for simple redirects

When every request matching a condition should move to one known URL, a direct return is clearer than a regular expression. For example, a permanently moved path can use a return 301 directive in the appropriate server or location context. Because this is an external redirect, the client makes a new request and the address bar changes.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Use rewrite for regular-expression URI changes

Use rewrite when the destination depends on captured parts of the incoming URI. Rules run in order, and a rewrite can cause NGINX to search for a new matching location. Keep patterns narrow and test both matching and non-matching paths. NGINX limits repeated rewrite processing to ten cycles; a rule that sends a URI back into a location that rewrites it again can therefore end in a rewrite-loop error rather than fixing the route.

Query-string handling needs deliberate attention. A replacement that includes a new argument string changes how existing arguments are handled; a trailing question mark has historically been used to discard the original arguments in configurations that support that syntax. Verify the behavior you want instead of assuming an Apache substitution has identical semantics.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use try_files for existence checks

try_files asks the filesystem question directly: does this candidate file or directory exist under the current root or alias? NGINX checks candidates in order. The last parameter is either an internal URI, a named location, or a configured status such as =404. This is usually safer and easier to reason about than translating every Apache condition into an if statement.

Converting common Apache patterns

Translate the behavior of a rule, not its spelling. The following examples show the decision involved in several common migrations.

“If it is not a file or directory, send it to the front controller”

Apache configurations often combine two conditions that exclude real files and directories before rewriting everything else. In NGINX, the direct equivalent is:

location / {
    try_files $uri $uri/ /index.php?$args;
}

Do not add a second rewrite for the same purpose. If the application entry point is app.php, a named proxy location, or another path, substitute that actual endpoint and ensure it has a matching handler.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

“Redirect an old path to a new fixed path”

For a known permanent move, prefer a direct return in the location that matches the old path. This tells clients and search engines that the destination is intentional. Use a temporary status only when the move is genuinely temporary.

“Capture part of a URI and build a new URI”

Use a carefully scoped regular-expression rewrite and test the resulting location. Confirm whether the operation should be internal or external, whether the original query string must survive, and whether the replacement URI can match the same rule again.

“Block access to a real file while allowing other files”

This is a policy decision rather than a front-controller fallback. Put the restriction in a specific location for the sensitive filename or extension, and return an explicit status. Do not place a broad deny rule where it intercepts application routes that should have reached the fallback.

Root, alias, and location matching: the three causes of false misses

Verify the effective root

try_files constructs filesystem paths using the root that applies in the current context. If the project is deployed at /var/www/example but public assets and the entry point are in /var/www/example/public, using the parent directory can make every candidate miss or expose files that should not be public. Set the root to the directory intended to be web-visible and keep the fallback there.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand alias path behavior

alias replaces the part of the URI matched by a location with a filesystem path. Its trailing-slash form and the location prefix must agree, or NGINX can construct an unexpected filename. When troubleshooting, temporarily map one known static URI and compare the resulting path with the actual file location. Avoid mixing a broad root assumption with an alias-specific location without checking which directive applies.

Check location precedence

NGINX does not simply choose the first block written in the file. Exact matches, longest prefixes, and regular-expression locations participate in selection. A PHP regular-expression location might process /index.php correctly while a more-specific prefix location handles the pretty URL without the intended try_files. Review all locations that could match the failing URI, including included files.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Symptom Likely configuration cause What to inspect
Homepage works; every nested route is 404 No application fallback in the general location try_files or equivalent in location /
Static files return 404 after adding a fallback Incorrect root or alias Effective filesystem path for one known asset
Only one directory fails A more-specific location overrides the general rule Prefix and regular-expression locations for that URI
Fallback URI itself returns 404 Entry point is absent or has no handler File location and PHP/upstream configuration
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A disciplined 404 troubleshooting sequence

  1. Reproduce one failing URI. Record the exact host, path, query string, and response status. Test a known static file from the same host so you have a control request.
  2. Confirm the virtual host. Check server_name, listening address, and port. If the request lands in a default server, changes to another host’s configuration cannot affect it.
  3. Validate before reloading. Run the deployment’s configuration test, commonly nginx -t. Fix every syntax or include error before attempting a reload.
  4. Reload through the service manager. Use the reload command appropriate to the operating system and package. A successful command means the new configuration was accepted; it does not prove that the intended location matches the request.
  5. Trace location and root selection. Re-read the matching server and location blocks, including snippets and included files. Confirm the root or alias and the order of try_files candidates.
  6. Check the fallback endpoint directly. Request /index.php, the named proxy location’s upstream path, or the chosen static fallback as appropriate. If that endpoint is 404, repair its file placement or handler before changing the original route.
  7. Inspect access and error logs. The access log shows the requested URI and status; the error log can reveal an open-file miss, permission problem, rewrite cycle, or upstream failure. Use the log paths configured for this NGINX installation rather than assuming a single distribution default.
  8. Compare file and directory permissions. A path that exists but cannot be traversed by the NGINX worker may appear as a miss or produce a different error. Check execute permission on parent directories and read permission on static files.
  9. Look for repeated rewrites. If the error log indicates a rewrite cycle or the URI changes repeatedly, remove overlapping rules, narrow the regular expression, or make the destination exempt from the source rule.

Changing application routes before completing these checks can hide a server-selection problem. First prove that NGINX reaches the intended fallback; then debug framework routing or controller code inside the application.

PHP-FPM details that commonly break a correct fallback

A front-controller line can be correct while the PHP location is not. The fallback URI must be handled by FastCGI settings appropriate to the installed PHP-FPM socket or TCP listener. The script filename passed to PHP-FPM must resolve under the same public root, and the location should not accidentally deny the entry point.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the general fallback and the PHP handler conceptually separate: location / decides whether a request is a real file or an application route; location ~ .php$ processes a PHP script. If the PHP regular-expression location is too broad, it may execute unintended files. If it is too narrow, the internal redirect to the entry point can land on a location that returns 404.

Query strings, trailing slashes, and internal versus external redirects

Preserve arguments intentionally

Applications often use parameters for searches, pagination, or signed requests. The common front-controller form /index.php?$args preserves the incoming arguments during the internal fallback. A regular-expression rewrite can replace, append, or discard arguments depending on its replacement syntax. Test a URL containing two representative parameters and inspect the application’s received request before deploying the rule.

Do not confuse a URI rewrite with a browser redirect

An internal redirect keeps the original address visible to the client and is normally appropriate for front-controller routing. A return 301 or return 302 sends a response that instructs the client to make another request. Using an external redirect merely to reach an application entry point can expose implementation details, create extra round trips, and alter canonical URLs.

Handle slash policy in one place

If the application requires or forbids a trailing slash, implement that policy with one narrowly scoped rule. Avoid combining a slash redirect, a front-controller rewrite, and a directory index rule that can redirect the same URI repeatedly. Test the bare path, the slash form, and a path containing a file extension.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Migration mistakes and their repairs

Mistake Why it fails Repair
Leaving .htaccess in the document root NGINX never reads Apache per-directory files Translate the behavior into loaded server and location blocks
Copying RewriteEngine, RewriteCond, or RewriteRule into NGINX syntax Those are Apache directives and cause an invalid or ignored configuration depending on where they are placed Choose return, rewrite, try_files, or an upstream handler based on intent
Translating every condition into if It obscures location selection and can introduce unexpected processing interactions Prefer try_files, a specific location, or a server-level rule when those express the requirement
Putting the rule in another virtual host The request never reaches the edited block Match the exact hostname and listening socket, then reload the active instance
Using the project root instead of the public root Filesystem candidates and the entry point are resolved from the wrong directory Set the effective root to the intended web directory and verify one static file and the fallback
Omitting the fallback handler The internal URI exists conceptually but has no PHP, proxy, or static handler Add and test the matching handler for the actual entry point
Dropping or duplicating query arguments Rewrite replacement syntax controls how the original query string is treated Test parameterized requests and specify preservation or replacement deliberately
Creating a rewrite loop The destination matches the source rule again Exclude the destination, narrow the pattern, or replace the rewrite with a direct return

Verification checklist before declaring the 404 fixed

  • The request is handled by the intended server_name and port.
  • The matching location contains the rule, or deliberately delegates to a named location that does.
  • The active root or alias resolves one known static file to the path you expect.
  • A real file is served without being sent through the application unnecessarily.
  • A real directory behaves according to your index and slash policy.
  • A nonexistent pretty URL reaches the intended application, proxy, or explicit 404 fallback.
  • The final fallback endpoint exists and has a working FastCGI, proxy, or static handler.
  • Query arguments survive or are replaced exactly as the application requires.
  • nginx -t succeeds before reload, and the reload affects the running instance.
  • Access and error logs show the expected status and no rewrite-cycle or upstream errors.

When a 404 is actually the correct result

Not every unknown path should be routed to an application. A static site may intentionally return =404. A security-sensitive location may reject direct access even when a file exists. An application may also return its own 404 after NGINX successfully forwards the request. Distinguish these cases by checking the response headers, access log, error log, and whether the fallback endpoint receives the request.

The practical rule is simple: use NGINX configuration to express the routing decision that Apache’s .htaccess previously supplied, and make the filesystem root, location match, fallback endpoint, and handler agree. Once those four pieces align, pretty URLs stop depending on an Apache file that NGINX cannot see.

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.