Hire a Writer
  • Home
  • Bookmarks
  • About
  • Privacy
  • Blog
Reading: How to remove .php or .html extensions using the .htaccess file
Onearticle Logo onearticle logo
→
  • Contact US
Sign In
Aa
OnearticleOnearticle
  • SEO
  • Technology
  • Gaming
  • Business
  • Freelancing
  • Tips and Tricks
  • Information
  • Online Earning
  • Business
  • Coding
  • Featured
Search
  • Categories
    • Business
    • Featured
    • Freelancing
    • Gaming
    • Information
    • Online Earning
    • SEO
    • Technology
    • Tips and Tricks
  • My Bookmarks
Have an existing account? Sign In
Follow US
Coding

How to remove .php or .html extensions using the .htaccess file

Umair Javed
Last updated: Jan 12
Umair Javed 53 Views
Share
3 Min Read
How to remove .php extension using .htaccess file
How to remove .php extension using .htaccess file

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.

Contents
What is a .htaccess file?How to remove the .PHP extension?How to remove the .html extension?Benefits of removing .php or .html extension.htaccess Editor Online ToolConclusion

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.

You Might Also Like

How to create a connection with a database in PHP

Type of cheekbones: low cheekbone vs high cheekbone

How To Make Money With Affiliate Marketing in 2022: A Beginner’s Guide

6 important steps to know before starting a business

TAGGED: coding, htaccess, html, php, Tips and tricks
Share this Article
Facebook Twitter Pinterest Whatsapp Whatsapp Copy Link
By Umair Javed
Follow:
I am a creative article writer working for the past 4 years. If you want engaging articles for your website, just send me a message.
Previous Article foodpanda Foodpanda is Good or Not? Genuine Review
Next Article How to write SEO Optimized Articles How to Write SEO-Optimized Article?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest News

10 Most Important Meta tags for SEO
10 most important meta tags for On-page SEO
SEO
How to create connection with database in php
How to create a connection with a database in PHP
Coding Tips and Tricks
How to write SEO Optimized Articles
How to Write SEO-Optimized Article?
SEO Tips and Tricks
How to remove .php extension using .htaccess file
How to remove .php or .html extensions using the .htaccess file
Coding
foodpanda
Foodpanda is Good or Not? Genuine Review
Business
Adsense Approval
AdSense Approval on custom website
Tips and Tricks
Why Bitcoin is down today?
Why Bitcoin is down today?
Information Technology
Non Custom Iphones in Pakistan
Non-Custom Iphones in Pakistan
Information

You Might Also Like

How to create connection with database in php

How to create a connection with a database in PHP

January 14, 2023 1.6k Views
types of cheekbones

Type of cheekbones: low cheekbone vs high cheekbone

August 18, 2022 128 Views
affiliate marketing 2022

How To Make Money With Affiliate Marketing in 2022: A Beginner’s Guide

August 8, 2022 106 Views
Business Ideas

6 important steps to know before starting a business

July 26, 2022 72 Views

Read. Write & Share Content

  • Made With Love
  • User Friendly
  • Tips & Tutorials

© Onearticle – All Rights Reserved.
We write Imaginations!

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Register Lost your password?