Can't hide .php and index.php in url with .htaccess

Been trying several methods online to create a .htaccess file to hide index.php and .php from urls with no luck. I get errors. It is not a WP site. Is there anyone who has succeeded with this out there?

sure, you can hide files an extensions with .htaccess. I’ve done it. Post your htaccess and let’s take a look.

I figured it out. I found out that 1.) all links within a site need to be absolute paths once the mod is in place; and 2.) although you remove the file extension (.php) from the links in the code, you do NOT remove them from the actual files. Thanks bobocat.

  1. is correct
  2. is not necessarily true

Please explain.

RewriteRule ^([^\.]+)$ $1.php [L,NC]

why would you need absolute paths?

This is the code I used to remove .php and add a slash on the end:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

After using this in .htaccess, my .css file wouldn’t load, and I found out that all my .js and .css files needed to be linked to via absolute paths. After removing the .php from links in each page, during testing, clicking on a link that was not an absolute path resulted in the browser believing the last page (with .php removed) was a folder, therefore clicking on a subsequent link within this non-existent folder resulted in an error.

put your css and js in a different directory and use different rewrites if you want to hide their extensions, although I don’t know why you would want to. hiding php obfuscates the technology you are using to make it harder to do something to your site, but there’s no reason i can think of to hide css or js as those are both completely visible to the user anyway.

This is going nowhere. I don’t want to hide the .js or .css. After I implemented the mod (rewrite), they’re external files couldn’t be found without absolute paths.

if you don’t want to hide them, the explicitly keep them out of your RewriteRule with a RewriteCond which ignores them. if you don’t want help, you are welcome to do it on your own.