使用查询字符串隐藏来自网址的.php扩展名

I am using .htaccess file for url rewriting . I've written all pages with .php extention and to hide them i am using this code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]`

But this hides when i write "www.example.com/abc.php" to "www.example.com/abc" . I want them to change automatically like when i click on a link

<a href="example.php">example</a>

then page link should open like "www.example.com/example" not "www.example.com/example.php"

Also how to hide "?var="hello" from all pages but variable should be sent to that page is that possible ?.

UPDATE

For example here i am using this

<?php 
if(isset($_GET['hi'])){
echo $_GET['hi'];
}
?>
<a href="a.php?hi=sdsdsd">a</a><br>
<a href="b.php">b</a><br>
<a href="c.php">c</a><br>
<a href="d.php">d</a><br>

I want what ever the page is should be accessed without extension and query string should be hided but must be accessed.

Use this .htaccess:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

For hidding ?val you should use POST instead of GET. And take a look on this article for .htaccess he has defined good in here.

Regarding hiding the query string. When the php page runs it can first check for a query string. If one is found you can pull the data out of the query string, store it somewhere (session probably) and redirect to the page with no query string (and no file extension for that matter).

However if you do this you're obscuring most of the benefits of using a query string.

To remove the php extension completly, you can use :

 RewriteEngine on

#1redirect "/file.php" to "/file"
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ %1 [NC,L,R]

#if the request is not for a dir
RewriteCond %{REQUEST_FILENAME} !-d

 #and the request is an existing php file
 RewriteCond %{REQUEST_FILENAME} !-f
 #then rewrite the request to orignal php file
 RewriteRule ^([^/]+)/?$ $1.php [NC,L]