Hi friends, You might wonder seeing some sites will not display any .php extension even though they developed the website using normal PHP script.
This can be achieved using htaccess. It’s damn simple and here is the code:
The below script will change your URL from:
From: https://www.yoursite.com/mysite.php
to: https://www.yoursite.com/mysite
Save the below script as (.htaccess) and upload it in your root folder or the folder you keep all your files (also work in sub-folder too!)
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php </IfModule>
NOTE: Better download notepad++ to save this file as .htaccess, because default notepad won’t allow it!
For your convenience I put a demo here you can check in both the ways:
with extension:
https://theonlytutorials.com/demo/myfile.php
without extension:
https://theonlytutorials.com/demo/myfile
I had put this code in the sub-folder (demo) of my site!
For your better convenience, I have given the Download too!
Great…. job.Thanks a lot…
Hii
I am creating a website in php but i am not able to hide extension
Please tell me step by step bcoz i m beginner not able to handle .htaccess file & how to create it.
cool_vishwas2010@rediffmail.com
hi vishwas,
Create a file called .htaccess (dot in front) and put the above code and upload it to your root folder.
I created .htaccess file and also uploaded on my root folder, when i run the file it gives error “Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.”
Can you tell me which hosting are you using?