.htaccess is a file which will help you to do
- Redirect the user to different page.
- Password protect a specific directory
- Block users by IP
- Preventing hot linking of your images
- Rewrite URIs
- Specify your own Error Documents
Removing Extensions
To remove the
.php
extension from a PHP file
for example the domain url is
example.com/home.php
and you want to change intoexample.com/home
so here you have to add the following code inside the .htaccess
file:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] </IfModule>
To remove the
If you want to remove the
.html
extension from a html fileIf you want to remove the
.html
extension from a html file for example example.com/home.html
to example.com/home
you have to add the following code inside the .htaccess
file:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
That’s it! You can now link pages inside the HTML document without needing to add the extension of the page. For example:
<a href="http://www.example.com/services">services</a>
No comments:
Post a Comment