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 desk9 min

How to Remove the .html Extension and Directory From URLs

A practical Apache and Nginx guide to extensionless URLs, directory-removal redirects, internal rewrites, SEO migration and testing.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make one clean URL—such as /about—the only public address. Permanently redirect requests for /about.html (and any retired directory path) to that address, then internally rewrite the clean request to the file or application route that serves it. Keep the old file on disk, exclude real files and directories from catch-all rules, and test every redirect before releasing the change.

What “removing .html” actually changes

A browser-visible URL and the resource stored on the server do not have to match. You can retain about.html in the document root while publishing /about. Two separate operations make that work:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • External redirect: A request for the old address, such as /about.html, receives HTTP 301 Moved Permanently and the browser moves to /about.
  • Internal rewrite: A request for /about is mapped inside the server to about.html without changing the address shown to the visitor.

Do not let both forms return successful 200 responses. Search engines and caches can treat them as separate URLs, creating duplicate content and splitting signals. Update your own links, XML sitemap and canonical tags to the chosen clean form; the redirect remains for people and crawlers that still use the old form.

Plan the URL migration before editing configuration

Choose one canonical shape

Decide whether the site will use a trailing slash. The examples below use no slash for files (/about), but a site can consistently choose /about/ instead. Apply that decision to redirects, internal links, canonical tags and the sitemap. Do not publish both slash variants as independent pages.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Inventory files, directories and routes

List every public .html page, existing directory and application route. Mark assets such as CSS, JavaScript, images, fonts and downloads; those are real files that must continue to be served directly. Record each old URL and its intended destination in a redirect table. This is especially important when deleting a directory segment: /docs/about.html, /about.html and /about might otherwise collide.

Check for slug collisions

Before deploying a rule that removes /docs, confirm that the destination slug is unique. If /docs/about.html and a separate root-level /about.html both exist, there is no single automatic destination. Resolve the naming conflict and write an explicit rule for each old URL.

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

Prepare a reversible change

Save the current Apache or Nginx configuration, deploy first on a staging host, and keep a copy of the redirect table. A redirect is cached by browsers and intermediaries; correcting a mistake can therefore take longer than correcting an ordinary page.

Apache: hide the extension with mod_rewrite

Where the rules belong

In a document-root .htaccess file, Apache evaluates patterns relative to that directory: the leading directory prefix is removed before the RewriteRule pattern is matched. The server must have mod_rewrite loaded and allow overrides (for example, an appropriate AllowOverride setting). If overrides are disabled, put equivalent directives in the virtual-host configuration instead.

Working document-root pattern

Place the redirect before the internal rewrite. The first rule examines THE_REQUEST, which contains the request line sent by the client. That prevents an internal rewrite from triggering the redirect again.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
RewriteEngine On

# Redirect the legacy extension to the canonical URL
RewriteCond %{THE_REQUEST} s/+(.+?).html(?:[?s]) [NC]
RewriteRule ^(.+).html$ /$1 [R=301,L,NE]

# Serve the real file without exposing the extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.html [END]

The redirect changes /about.html to /about. The second block runs only when the requested path is not already a file or directory and when the corresponding .html file exists. The !-f and !-d checks protect assets and real directories from the catch-all rule. Apache 2.4 supports the END flag, which stops per-directory rewriting for the request; on an older version, use the equivalent stopping behavior appropriate to that installation.

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

Why the redirect condition matters

If the internal mapping simply rewrote /about to about.html and the redirect matched every URI ending in .html, Apache could redirect its own internal result and create a loop. THE_REQUEST still contains GET /about after the internal rewrite, so the legacy redirect does not fire.

Query strings and encoded paths

Because the redirect substitution has no new query string, Apache normally carries the original query string forward: /about.html?ref=mail becomes /about?ref=mail. Test this behavior on your exact Apache version and any additional rewrite modules. Use NE when you need reserved characters in the redirect target not to be escaped a second time, and restrict accepted path characters rather than allowing arbitrary user input.

Subdirectory .htaccess files

A file at /docs/.htaccess sees about.html, not docs/about.html, as its rule pattern. Adjust substitutions and file-existence tests for that context. If the desired public URL is at the site root, a document-root rule is usually clearer and avoids ambiguity about relative paths.

Nginx: use server-block rules and try_files

Configuration location

Nginx has no Apache-style per-directory .htaccess. Put the directives in the relevant server block, validate the configuration, and reload Nginx using your operating system’s service procedure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Static HTML pattern

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

# Legacy extension redirect
location ~ ^/(.+).html$ {
    return 301 /$1;
}

try_files checks the requested path, then a directory form, then the same path with .html appended; if none exists, Nginx returns 404. The regular-expression location sends an old extension URL to the extensionless path. A return redirect with no replacement query string normally retains the original arguments, but verify with a request such as /about.html?ref=mail.

Place more specific locations and application rules carefully. If a real file or directory should win, ensure the location and try_files order does not route it into the HTML fallback. After editing, run Nginx’s configuration test command supplied by your installation, then reload rather than restarting blindly.

Application and front-controller sites

For a framework or CMS, do not append .html to every unknown request. Route dynamic URLs to the application’s front controller. A common WordPress-style pattern is:

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

This preserves existing files and directories, then passes other paths—including clean page slugs—to index.php. Keep the legacy .html redirect separate, and follow the application’s documented routing rules instead of combining a static-file fallback with dynamic routing indiscriminately.

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

Removing a directory segment is a separate migration

Changing /docs/about.html to /about is not merely extension hiding. It removes a path component and therefore needs an explicit old-to-new mapping. Apply this rule before a generic extension redirect.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Apache example

# Directory removal: place before the generic .html redirect
RewriteRule ^docs/(.+).html$ /$1 [R=301,L]

With this rule, /docs/about.html redirects directly to /about, not first to /docs/about. Add one rule for every exceptional rename when the destination cannot be derived safely from the old path.

Nginx example

rewrite ^/docs/(.+).html$ /$1 permanent;

After the external redirect, the normal extensionless lookup or application route serves the destination. Confirm that the root-level slug is not already assigned to another resource. If it is, choose a different destination and encode that decision explicitly.

Keep a redirect map for irregular paths

Catch-all expressions are suitable only for predictable one-to-one changes. Maintain a map for renamed, merged or deleted pages, and monitor server logs and analytics for requests that still hit the old directory. A redirect to an unrelated page is worse than a deliberate 404; send users to the closest genuine replacement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

SEO and link integrity after the change

Make every current signal use the canonical URL

  • Change navigation, breadcrumbs, pagination and in-content links to the clean form.
  • Regenerate the XML sitemap with only canonical URLs.
  • Set each page’s canonical tag to its clean URL, including the chosen slash policy.
  • Keep the old URLs redirecting with a permanent status; do not list them as canonical URLs.

Preserve useful query parameters

Tracking and functional parameters often arrive on old links. Verify that the redirect carries them to the new path and that the destination application still interprets them. If a parameter must be discarded for policy reasons, do so deliberately in a dedicated rule rather than accidentally by rewriting every query string.

Avoid redirect chains

Each old address should reach its final canonical URL in one hop. For example, map /docs/about.html directly to /about instead of redirecting first to /docs/about and then to /about. Chains add latency and make troubleshooting harder.

Deployment and test checklist

  1. Deploy the rules in the right context. Use .htaccess only when Apache overrides are enabled; otherwise use the virtual-host configuration. Put Nginx directives in the server block.
  2. Test a legacy page. Request /about.html and confirm one permanent redirect whose Location is /about.
  3. Test the clean page. Request /about and confirm a final 200 response with the expected content.
  4. Test both slash forms. Decide whether /about/ redirects, resolves as a directory, or is otherwise canonical; ensure the result is consistent rather than two competing pages.
  5. Test query strings. Check an old URL with parameters and verify that required arguments survive.
  6. Test real files and directories. Request a stylesheet, script, image, download and an existing directory. None should be captured by the HTML fallback.
  7. Test directory removals. Check every old directory URL in the redirect table, including paths with nested segments.
  8. Test unknown paths. A nonexistent extensionless path should return the application’s intended response or a genuine 404, not a fabricated page.
  9. Test encoded characters. Try spaces, percent-encoded characters and non-ASCII slugs that the site legitimately supports. Look for double encoding or unsafe decoding.
  10. Check for loops and chains. Follow redirects with a client that shows each hop. The final response should be the canonical URL with status 200.
  11. Review logs after release. Watch 404s, repeated redirects, asset failures and requests for old paths. Add or correct explicit mappings where real traffic exposes an omission.

Troubleshooting common failures

The clean URL returns 404

On Apache, verify that the file-existence condition points to the actual document root and that the requested path matches the rule’s relative pattern. On Nginx, confirm that $uri.html resolves to the intended file and that a higher-priority location is not intercepting the request. For an application, check the front-controller route instead of adding another static fallback.

The browser keeps redirecting

Inspect the response chain. On Apache, a redirect that matches the internally rewritten filename usually means the rule is not checking THE_REQUEST or the conditions are in the wrong order. On Nginx, look for overlapping regular-expression locations or a second redirect elsewhere in the server or application configuration. Clear a cached permanent redirect only after the server rules are corrected; test with a fresh client or a command-line HTTP client.

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

Images, CSS or JavaScript stop loading

This usually indicates that a catch-all rule is rewriting real assets. Keep the !-f and !-d exclusions in Apache, and place try_files candidates in the correct order in Nginx. Check the browser’s failed request path rather than changing the page’s HTML first.

The directory rule produces the wrong page

Check for a slug collision and rule ordering. A specific /docs/... mapping must run before a generic .html redirect, and its destination must be a resource that actually exists. Replace a broad expression with explicit mappings for exceptional pages.

Query parameters disappear

Inspect the redirect’s Location header. A substitution that introduces a question mark replaces the original query string; one without a new query string generally preserves it, subject to server and module behavior. Correct the rule and retest both legacy and canonical requests.

Unsafe or unexpected redirects appear

Do not build redirect targets from unrestricted user input. Constrain matches to the site’s own host and expected path characters, and reject traversal-like or malformed values. Apache’s mod_rewrite documentation specifically cautions that redirects based on unvalidated input can create unsafe redirects or unintended path access.

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.

Apache and Nginx at a glance

Concern Apache Nginx
Rule location .htaccess when overrides are enabled, or virtual-host configuration Server-block configuration; no per-directory .htaccess
Legacy redirect RewriteCond plus RewriteRule with R=301 return 301 or rewrite ... permanent
Extensionless file lookup Internal RewriteRule guarded by file and directory checks try_files $uri $uri/ $uri.html =404 for static pages
Application routing Use the application’s rewrite/front-controller rules after excluding real files and directories Use the framework’s front controller, commonly via try_files ... /index.php?$args
Main collision risk Relative patterns and broad rules can capture assets or create loops Location precedence and overlapping regex locations can capture the wrong request
Directory removal Explicit RewriteRule placed before the generic extension redirect Explicit rewrite placed before broader routing

When not to remove the directory or extension

A URL change is worthwhile only when the cleaner structure serves a real maintenance, usability or information-architecture goal. If an established directory conveys meaningful hierarchy, removing it can create unnecessary redirects and collision work. Likewise, do not rename thousands of stable URLs solely for appearance when the existing structure is clear and error-free. If you do proceed, treat it as a migration: preserve one-to-one redirects, update every internal signal, and keep monitoring after launch.

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 *

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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.