too long

I never really have used mod re write and I am trying to understand the best way to implement it. removing the .php extension. i found this code

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

problem is that if the link is to domain.com/index.php it wont re write it domain.com/index

Also if i do the link domain.com/index the person can still add the .php and it still works fine.

I would like to know the proper way.. do i have to hard code the urls in the html or is there something that can do it automatically?

I dont want them to be able to add the .php to the end

You need an additional rule to remove .php . The rule you are using just allows you to access php files without their extension but doesn't remove the extension. To remove the .php you can use :

RewriteEngine on
#1) redirect "/file.php" to "/file"
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [L,R,NE]
#2) internally map "/file" back to "/file.php"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php