New to our community ?

Discover a world of possibilities! Join us and explore a vibrant community where ideas flourish and connections thrive.

One of Our Valued Members

Thank you for being part of our community. Your presence enriches our shared experiences. Let's continue this journey together!

Home php codes How to hide extension of html and php file.?

How to hide extension of html and php file.?

0

welcome back to shortlearner.com , In this tutorial  we will see how to hide extension of files using .htaccess
before start learning first of all we should  know about .htaccess file
what is .htaccess

hide extension of url using htaccess
in a simple words we can say that the .htaccess is a configuration file for use on web servers running the
Apache Web Server software. When a .htaccess file is placed in a directory
which is in turn ‘loaded via the Apache Web Server’,
then the .htaccess file is detected and executed by the Apache Web Server software.

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Benefits of using .htaccess

  • 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

In this tutorial we make 3 php pages and hide there extensions using .htaccess file.
index.php

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Remove .php extension with .htaccess by http://mainvps.shortlearner.com/</title>
         
        
        
    </head>
<body>
 
<center>

<div id="menu">
<ul>
	<li><a href="index">home</a></li>
    <li><a href="login">login</a></li>
    <li><a href="signup">signup</a></li>
  
</ul>
</div>

<div id="body">

<h1>This is index.php page | see the url in addressbar</h1> <br />


</div>
</center>
 
</body>
</html>

Signup.php

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Remove .php extension with .htaccess by http://mainvps.shortlearner.com/</title>
         

        
    </head>
<body>
 
<center>

<div id="menu">
<ul>
	<li><a href="index">home</a></li>
    <li><a href="login">login</a></li>
    <li><a href="signup">signup</a></li>
   
</ul>
</div>

<div id="body">

<h1>This is signup.php page | see the url in addressbar</h1>

</div>
</center>
</body>
</html>

Login.php

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Remove .php extension with .htaccess by http://mainvps.shortlearner.com/</title>
         
        <link rel="stylesheet" href="style.css" type="text/css" />
        
    </head>
<body>
 
<center>

<div id="menu">
<ul>
	<li><a href="index">home</a></li>
    <li><a href="login">login</a></li>
    <li><a href="signup">signup</a></li>
   
</ul>
</div>

<div id="body">

<h1>This is login.php page | see the url in addressbar</h1><br />



</div>
</center>
</body>
</html>

Save below code with .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html


</IfModule>