What is a .htaccess file?
Basically .htaccess file is a configuration file that determines the features of the Apache server. It’s an ASCII file that you can create in any text editor or IDE. By default, all settings are configured, but one may want to make changes. Or enable advanced features according to needs.
By using the .htaccess file, you can perform many advanced features like:
- Redirect or Rewrite URLs
- Protect a Directory/Page using a password
- Block Visitors by IP Address
- Stop hotlinking of your website images
- Show Custom Error Documents
It is just .htaccess and not an extension or ending part of a filename, like the empty name of a file with the extension .htaccess.
Read More About Coding here
How to remove the .PHP extension?
By default, your apache server is configured to show file extensions like .php, .HTML, or .htm. If you want to change your URL from www.yoursite.com/index.php to www.yoursite.com/index then follow these steps:
- Step 1: Create a Text file.
- Step 2: Paste the following code in the text file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
- Step 3: Save the file with the name .htaccess (in lowercase) with the empty file name.
- Step 4: Now our file is ready. Upload this file to the root directory of your website. It will remove .php extension from all pages placed under the root directory.
How to remove the .html extension?
To remove .HTML extension, you don’t have to change much of this code. Just replace the last line with the following:
RewriteRule ^([^\.]+)$ $1.php [NC,L]
and it’s done!
Now your website pages can be accessed without extensions like .php or .HTML. So now you can visit www.mysite.com/index.php using the URL www.mysite.com/index.
Benefits of removing .php or .html extension
Removing the file extensions gives us a number of benefits. The most useful is that you can link your pages without remembering the exact URL. You can now place links something like this:
BEFORE
<a href="mysite.com/index.php"> OR <a href="mysite.com/index.html">
AFTER
<a href="mysite.com/index">
Moreover, removing extensions helps a website rank higher in SERP. This is because the visitor can remember the website addresses more conveniently.
.htaccess Editor Online Tool
For those who are not tech savvy or don’t want to touch coding at all, there is an online tool available .htaccess editor which can do the same work.
Conclusion
I hope this article will give you what you are looking for. Removing file extensions make your website look more professional and clean. But messing with configuration files can result in fatal errors. So it’s better to take a complete backup before doing any changes.