htaccess Method to Remove a .php and .html extensions

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

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
#RewriteRule ^([a-z]+)\/?$ $1.html [NC]
</IfModule>
view raw.htaccess hosted with ❤ by GitHub
That’s all 🙂  If you Have Any Doubt Related in this tutorial please Feel free to comment here I will help you

Comments

Popular posts from this blog

Send PHP E-mail From Gmail SMPT

NewsDog WeMedia - Write smarter, grow faster and earn better

7 Latest Trends In The Logo Designing World