Removing www and .php not working

So I insert following code in my apache.htaccess file in order to remove www and php.

Whats wrong here?

This is my whole file


ErrorDocument 500 /500.php
ErrorDocument 404 /404.php

# force non-www domain
RewriteCond %{HTTP_HOST} ^www\\.example\\.com$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]

#RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [QSA,L]

In what way is it not working?

You type in the URL (…) and you expect (…) to happen, but actually (…) happens.

I type a URL with www and I want it to not show www even when I type. I want it to be without www. Same thing is with .php which always shows up.

Website is running on basic linux server, if that helps.

The problem I’m having is that the code you posted works just fine… depending on what you’re trying to do. Which is why I asked you to clarify, “In what way is it not working?” It’s not helpful enough to just say that you “type a URL.” Nor is it helpful enough to say, “I want it to be without.” You need to show us the specific URL you’re typing, and you need to tell us the specific behavior you expect. Are you hoping for an external redirect? That is, the server sends back a redirect response and the browser re-fetches from that new location. This tends to have the effect of changing the URL in the address bar. Or are you hoping for an internal rewrite? That is, you type in an extensionless URL, and the server maps that extensionless path to a real file on your server. This lets you leave .php off the URL but still get the content of the .php page.