October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Remove File Extensions from URLs Safely

Learn how to make extensionless URLs canonical with a permanent redirect and internal routing on Apache or NGINX.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To remove .html or .php from a URL, make the extensionless address canonical: permanently redirect the old address to it, then internally route that clean path to the file or application that serves the page. This is a server-routing change, not simply a file rename. “Extension” is the standard spelling.

How extensionless URLs work

Two separate actions are needed. A redirect tells the browser to request a different address, so visitors and search engines move from /page.html to /page. An internal rewrite routes a request for /page to the existing file or application handler without changing the address shown in the browser. Apache describes mod_rewrite as a way to modify incoming requests dynamically using regular-expression rules in its mod_rewrite introduction; its URL remapping guide distinguishes redirects from internal mapping and recommends a dedicated Redirect when available.

Keep the two operations distinct: redirect old extension-bearing URLs to the chosen clean form, then map clean requests internally. Without the redirect, both forms may remain accessible; without the internal mapping, the clean address may not resolve to the intended content.

Apache HTTP Server

Apache rules can be placed in server or virtual-host configuration, or in per-directory configuration such as .htaccess. The matching path differs by context: in server and virtual-host context, the pattern includes the URL path; in per-directory context, Apache strips the directory prefix before matching. Query strings are not part of a RewriteRule pattern. See the Apache introduction.

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

A safe setup separates the permanent redirect from the internal mapping and checks that the target exists where appropriate. Apache’s extension-change example uses -f to test for the new file and !-f to test that the old file is absent, helping avoid collisions. The exact rule depends on whether pages are physical files or application routes, so adapt the paths to your site rather than pasting a generic rule blindly.

If rules are in .htaccess or a <Directory> block, verify the per-directory path base. Apache notes that RewriteBase may be needed when the URL path does not map directly beneath the document root; see the mod_rewrite directive documentation.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

NGINX

In NGINX, use a permanent return 301 (or an equivalent permanent redirect) for the old extension URL, then route the clean path internally using a rewrite or a try_files-style fallback suited to the site’s file and application layout. NGINX’s rewrite module documentation describes return status codes and rewrite processing.

Rule order matters. NGINX processes rewrite directives in order; last stops the current rewrite sequence and begins a new location search, while break stops rewrite processing in the current context. Put canonical redirects before internal fallbacks and check that the resulting flow cannot loop. Refer to the NGINX rewrite module guide when choosing the directive behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Apache and NGINX compared

Concern Apache HTTP Server NGINX
Rule syntax mod_rewrite uses a regular-expression pattern, substitution, and optional flags; query strings are not part of the pattern. Apache documentation rewrite uses a regular expression and replacement URI; return can issue a redirect. NGINX documentation
Where configured Server or virtual-host configuration, or per-directory contexts such as .htaccess and <Directory>; the path used for matching depends on context. Apache introduction In NGINX configuration contexts using the rewrite module; directive order and location processing affect the result. NGINX documentation
Permanent redirect A dedicated Redirect is the cleanest approach when server configuration access is available. Apache remapping guide Use return 301 or another appropriate permanent redirect. NGINX documentation
Internal mapping and safeguards Keep the clean-path mapping internal; existence checks such as -f and !-f can help prevent collisions. Apache remapping guide Use an internal rewrite or try_files-style mapping matched to the site’s layout; last and break have different effects. NGINX documentation

Test the change before relying on it

  1. Choose the canonical form. Decide on extensionless paths, one trailing-slash policy, and one scheme and host. Ensure other variants redirect to that same form.
  2. Check the old address. Request a page such as /page.html or /page.php. It should return a permanent redirect to the intended clean URL, not serve duplicate content.
  3. Check the clean address directly. Request /page in a fresh browser or HTTP client. It should serve the expected page while the browser continues to show the clean address.
  4. Check edge cases. Test query strings, nested directories, assets, and a page whose target file does not exist. A missing target should return a genuine 404 rather than redirecting repeatedly or falling through to unrelated content.
  5. Review the configuration context and order. On Apache, confirm whether the rule is in server, virtual-host, .htaccess, or <Directory> context and whether RewriteBase is needed. On NGINX, verify directive order and the effects of last or break.

Common problems to avoid

  • Renaming files without changing routing: removing a suffix from the visible address does not itself connect that address to the existing file or application.
  • Keeping both versions live: redirect the old extension URL rather than serving the same page at two indexable addresses.
  • Redirecting a clean URL back to itself: separate redirect and internal rewrite rules, and test the full request path to catch loops.
  • Applying a rule too broadly: use existence checks or routing conditions suited to the site’s layout so that real files, application routes, and missing paths are handled intentionally.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.