How to Remove .html and .php Extension in the URL using .htaccess
Submitted by nurhodelta_17 on Wednesday, March 28, 2018 - 23:17.
Creating our Pages
First, we are going to create our sample pages. Create the ff files and paste the codes below it. index.html
login.php
- <?php
- echo "This is the Login Page";
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>How to Remove .html and .php Extension in the URL using .htaccess</title>
- </head>
- <body>
- <a href="index">Home</a>
- </body>
- </html>
Creating our .htaccess File
Lastly, we create our .htacess file. Create a new file, name it as .htaccess and paste the below codes.- <IfModule mod_rewrite.c>
- RewriteEngine on
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME}.php -f
- RewriteRule ^(.*)$ $1.php
- #RewriteRule ^([a-z]+)\/?$ $1.php [NC]
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME}.html -f
- RewriteRule ^(.*)$ $1.html
- #RewriteRule ^([a-z]+)\/?$ $1.html [NC]
- </IfModule>
Add new comment
- 376 views