htaccess Method to Remove a .php and .html extensions


htaccess Method to Remove a .php and .html extensions

htaccess Method

In this tutorial we are going to see about htaccess Method to Remove a .php and .html extensions

What is .htaccess ?

.htaccess files are a simple ASCII text file with the name .htaccess.its Help to control the behavior of your website or control a specific directory

Uses Of htaccess File

  • website redirection
  • Speed Optimization
  • Deny Access the IP
  • Lock the File Directory
  • Remove the File extension’s
  • Password product the specific page

For More About htaccess files Please read it on Apache’s website ok let’s come to our topic.in this tutorial we are going to see about  Remove a .php and .html extensions by using htaccess file.

Remove .html Extension

Mostly we created a HTML website like this www.website.com/user.html if you want a SEO friendly URL like this www.website.com/user Means use the Below code Before check whether you have .htaccess file on your server or create a .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html-f
RewriteRule ^(.*)$ $1.html
</IfModule>

Remove .PHP Extension

same as the Above Method mostly u create a PHP file like this www.mywebsite.com/login.php after using this method u can access the URL like this www.mywebsite.com/login

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>


Adding Trailing Slash At The End of URL like WordPress

The above steps help you remove the file extensions from the URL

without trailing slash

www.mywebsite.com/login

with Trailing Slash

www.mywebsite.com/login/

Complete htaccess code for remove file extension + Add a trailing slash like WordPress

 

That’s all 🙂  If you Have Any Doubt Related in this tutorial please Feel free to comment here I will help you

Also  read – PHP redirect Method to another page


Was this article helpful?
Thanks!

Your feedback helps us improve Allwebtuts.com



3 Shares
+11
Tweet
Share1
Pin1
Stumble