• We just launched and are currently in beta. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

How to Remove .html and .php Extension in the URL using .htaccess

Corpse2.0

Modder
C Rep
0
0
0
Rep
0
C Vouches
0
0
0
Vouches
0
Posts
134
Likes
15
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
Creating our Pages

First, we are going to create our sample pages. Create the ff files and paste the codes below it.

index.html
  1. <!DOCTYPE html>
  2. <html

    >
  3. <head

    >
  4. <meta

    charset

    =

    "utf-8"

    >
  5. <title

    >

    How to Remove .html and .php Extension in the URL using .htaccess</

    title

    >
  6. </

    head

    >
  7. <body

    >
  8. <a

    href

    =

    "login"

    >

    Login</

    a

    >
  9. <p

    >

    This is the index Page</

    p

    >
  10. </

    body

    >
  11. </

    html

    >

login.php
  1. <?php
  2. echo

    "This is the Login Page"

    ;
  3. ?>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="utf-8">
  8. <title>How to Remove .html and .php Extension in the URL using .htaccess</title>
  9. </head>
  10. <body>
  11. <a href="index">Home</a>
  12. </body>
  13. </html>

Creating our .htaccess File

Lastly, we create our .htacess file. Create a new file, name it as .htaccess and paste the below codes.

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on

  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteCond %{REQUEST_FILENAME}.php -f
  5. RewriteRule ^(.*)$ $1.php
  6. #RewriteRule ^([a-z]+)\/?$ $1.php [NC]


  7. RewriteCond %{REQUEST_FILENAME} !-d
  8. RewriteCond %{REQUEST_FILENAME}.html -f
  9. RewriteRule ^(.*)$ $1.html
  10. #RewriteRule ^([a-z]+)\/?$ $1.html [NC]

  11. </

    IfModule>

That ends this tutorial. Happy Coding :)


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

343,000

343,008

Top