Hide .php Extension From Browser Address Bar


/ Published in: Apache
Save to your folder(s)

Add source to .htaccess file and server will hide .php extensions. href tags must reference the file name without the extension .php in order to work properly.


Copy this code and paste it in your HTML
  1. Options +FollowSymLinks -MultiViews
  2. # Turn mod_rewrite on
  3. RewriteEngine On
  4. RewriteBase /
  5.  
  6. # To externally redirect /dir/foo.php to /dir/foo/
  7. RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
  8. RewriteRule ^ %1 [R,L]
  9.  
  10. # To internally redirect /dir/foo/ to /dir/foo.php
  11. RewriteCond %{DOCUMENT_ROOT}/$1.php -f
  12. RewriteRule ^(.*?)/?$ $1.php [L]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.