I have seen this question posed everywhere but not with the answers that solved it for me. So I played and played and discovered, da dah, the problem. Let's say you log into newspaper.com/sports and all you see is code. That's because the correct url is newspaper.com/sports.html or sports.htm or sports.php. Chrome and others, because there is no newspaper.com/sports(with no dot.extension) finds the html or htm or php and displays its code instead of the page. You can correct this, if you're using File Manger, by changing your /sports.html to /sports(with no dot.extension), or, better yet, save it as both. It you don't know what File Manager is, just be sure to enter the full URL instead of the quickie and you'll see all the pretty colors and text instead of just the courier type style.

Dani AI

Generated

Short summary and practical checklist.

What saw (adding “.html” made the page render) is a common symptom, but the real cause is the server’s behavior, not the browser. When a browser shows raw HTML or PHP source instead of rendering the page the server either sent the wrong Content-Type (for example text/plain) or did not execute server-side code (PHP/ASP) and served it as a static file. ’s note about rewrite rules and default documents is correct: the server decides what to serve for /sports, not the browser.

Quick diagnostic steps (reproduce, then inspect):

  • Check response headers in DevTools > Network or with curl to confirm the Content-Type.
    curl -I https://example.com/sports
    # look for: Content-Type: text/html; charset=UTF-8
  • Deploy two tiny test files: test.html (plain HTML) and test.php (simple PHP). If test.html renders but test.php shows code, the PHP handler is not configured or broken.

Common fixes (pick what matches the environment):

  • If Content-Type is wrong for static HTML, ensure the server’s mime settings include .html -> text/html. On Apache, avoid renaming pages to remove extensions; instead enable MultiViews or add a rewrite.
  • To map extensionless URIs to existing .html files (Apache .htaccess example):
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)$ $1.html [L]
  • For Nginx, prefer try_files so /sports falls back to /sports.html:
    location / {
    try_files $uri $uri.html $uri/ =404;
    }
  • If PHP files are returned as source, check that PHP (mod_php or PHP-FPM) is installed and mapped, and inspect server error logs. On hosted platforms, contact support.

Safety note: serving unprocessed server-side code can expose secrets. If that happened, stop public access, fix the handler, and rotate any exposed credentials. Renaming files to hide extensions is only a band-aid; the long-term fix is correct server configuration or a proper rewrite. ’s “What the heck?!” reaction is warranted — this is a server-side problem, not a browser bug.

Recommended Answers

All 3 Replies

I'm a little bit confused by what you're saying, but let me try to explain to you how it works:

When the browser request newspaper.com/sports, the WebServer (IIS or Apache or etc) will first see if there's any Rewrite Rules that match /sports.

If there's no rule that match /sports, then the WebServer will think that /sports is an directory (because there's no extension and the WebServer handle each requested file by it's extension, so it knows what and how to treat the file - extensions are related to MIME Type configs and Module Handlers).

If the directory /sports exists, then the WebServer will try to find the default document for that directory (index.html, default.aspx, index.php and etc). If the default document exists (default document configuration and also the physical default doc), then the WebServer will parse this file and return it's content.

If the directory /sports exists but there's no default document, then WebServer will either list the directory contents (if the WebServer is configured to do so) or it'll return the error 403 - 'Directory Listing not Permitted'

Last but not least, if the directory doesn't exists at all the WebServer will return 404 - 'Not Found'.

If you don't know them, rewrite rules make possible /sports to be redirect to /sports.html or even /sports/volley to /sports?id=volley.
Rewrite rules are very usefull. Most sites that have friendly urls use rewrite rules.

Anyway, to help you out you need to show us what 'code' are you seeing instead of the page itself.

What the heck?!?

Thank you AleMonterio. You have expanded my understand and knowledge.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.