Protecting PHP projects using .htaccess file |
Lets starts with hiding .php extension. But for that we need to create .htaccess file first. It is very simple to create. Follow the instruction to create .htaccess file.
- Open you notepad
- Save the file with .htaccess.
- Upload the file on root directory.
Hiding .php extension
if you need to hide .php extension like (http://yousitename.com/home.php to http://www.yousitename.com/home ) you just need to add the following code into your .htaccess file
RewriteEngine on
RewriteRule ^(.*)\$ $1.php
With .htaccess we can also rewrite extension like .html .asp etc
For this you just need to add following code into you htaccess file
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php (Replace .html with any you desired extension to show)
Url rewriting
You can also rewrite you ugly and non-user-friendly urls to beautiful and user-friendly urls like (http://www.yousite.com/category.php?name=categoryname ) to (http://www.yousite.com/categoryname) for this you need to add the following like of codes into your .htaccess file
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1
0 Comments