htaccess – How to remove .php, .html, .htm extensions with .htaccess
we are going to show you how to remove .php, .html, .htm extensions with .htaccess file.Remove .php, .html, .htm Extensions
To remove the.php extension from a PHP file as an example your-domain.com/your-page.php to your-domain.com/your-page you’ve got to feature the subsequent code within the .htaccess file ::RewriteEngine On
RewriteCond % !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
If we would like to get rid of the
.html extension from a HTML file as an example your-domain.com/your-page.html to your-domain.com/your-page you just ought to alter the last line from the code higher than to match the computer filename ::RewriteRule ^([^\.]+)$ $1.html [NC,L]
That’s it! you’ll currently link pages within the HTML document without having to feature the extension of the page.
example:
<a href="http://your-domin-name.com/your-dir" title="your-dir">NAME-OF-LINK</a>
Adding a trailing slash at the tip
I received several requests asking a way to add a trailing slash at the tip. Ignore the primary piece and insert the subsequent code.The primary four lines modify the removal of the extension and therefore the following, with the addition of the trailing slash and redirecting.
Link to the HTML or PHP file as shown higher than. Don’t forget to alter the code if you would like it applied to associate HTML file.
RewriteEngine OnRewriteCond % !-fRewriteRule ^([^/]+)/$ $1.phpRewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.phpRewriteCond % !-fRewriteCond % !-dRewriteCond % !(\.[a-zA-Z0-9]|/)$RewriteRule (.*)$ /$1/ [R=301,L]
Some individuals asked however you’ll take away the extension from
each HTML and PHP files. I haven’t got a writing resolution for that.
But, you’ll simply modification the extension of your HTML file from
Note For
Attention For
so as to get rid of the extensions you wish to modify MultiViews before.
But, you’ll simply modification the extension of your HTML file from
.html or .htm to .php and add the code for removing the .php extension.Conclusion for Removing Extensions
For those that don’t seem to be thus skilled with.htaccess files there’s an internet tool for making .htaccess files. it’s pretty smart for novice users and really straightforward to use. Visit their web site.
Note For GoDaddy User
Attention For GoDaddy users only ::
so as to get rid of the extensions you wish to modify MultiViews before. The code ought to appear as if this ::
Options +MultiViewsRewriteEngine OnRewriteCond % !-dRewriteCond % !-fRewriteRule ^([^\.]+)$ $1.php [NC,L]If you’re disquieted that search engines may index these pages as duplicate content, add a canonical meta tag in your HTML head ::
<link rel="canonical" href="https://your-domin-name.com/your-dir/other-data">
No comments:
Post a Comment