Hi Friends, Today i will tell you how to remove or change php html extensions using htaccess file. It is so easy and simple, but we need to remove the extension like .php or .html. It helps to covert your url to SEO friendly url.
URL: http://www.website.com/user.php or http://www.website.com/user.html
SEO Friendly URL: http://www.website.com/user or http://www.website.com/user
If you want to use SEO friendly URL for your website then it is important to remove special characters and extensions from the url.
You have to follow some steps to remove or change php html extensions using htaccess file. These steps are
Steps1: You have to create a .htaccess file in the root folder and write some code like
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
</IfModule>
Step2: Most of the time it is already created named htaccess.txt, Change the name of this file .htaccess. and check in the php.ini file your mod_rewrite should be enabled.
Step3: Now you have to know how to remove the extensions after creating the file. Write these code.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Remove .php extension from url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Remove .html extension from url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
Step5: Now Check the URL of your website.
Before placing the code
http://www.website.com/user.php
http://www.website.com/user.html
After Placing the code
http://www.website.com/user
Step6: Now Enjoy your website without extension like .php or .html
If you want a slash after your URL like http://www.website.com/user/
Follow the below steps.
Step1: Create .htaccess file in the root folder.
Step2: Place the below code in the .htaccess file and add it between
<IfModule mod_rewrite.c> and </IfModule>
# Add slash at end of the url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
Step3: Check your URL after applying the code.
Before placing the code
http://www.website.com/user.php
http://www.website.com/user.html
After Placing the code
http://www.website.com/user/
Step4: Enjoy your Website without extension .php or .html with slash.
Read About Other Interesting Things below.
Categories: Social Media Optimization
Leave a Reply