Url friendly with .htaccess

0
65
Url friendly with .htaccess

This code what it does is to extract the extensions in the url.

With this you get

  • Url more friendly for users and search engines
  • Remove extension from the address bar
  • Hide files

For this you have to create a file with the name “.htaccess”

Activate RewriteEngine

<IfModule mod_rewrite.c>
# Activar RewriteEngine
RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
 
RewriteRule ^(.*)$ $1.php
</IfModule>

Where it says “RewriteBase /” indicates that the base directory is the root. If for example a folder called “base” we would do “RewriteBase / base”.

What is in bold that is “.php” you have to edit it by the extension that your files have, for example php, html, asp.

Now upload it to the root of your website and try it this way

www.yourweb.com/index.php
I would have to enter the same if you put
www.yourweb.com/index

If you can manage them a bit, you can do www.yourweb.com/1/my_first_post


LEAVE A REPLY

Please enter your comment!
Please enter your name here