Showing posts with label .htaccess. Show all posts
Showing posts with label .htaccess. Show all posts

Sunday, May 29, 2011

How to restrict users from accessing files & directory level(Protect directory) using .htaccess


Hello Friends,
Today i faced a situation where i have to restrict or deny users from accessing files and folders of my web application directly by entering URL in browser which contain very important contents likeimages,pdfs,docs,etc. For this what i need to do is to protect the files and folders(directory) which contains images,pdfs and docs. We can restrict users from accessing files,folders and subfolders by using.htaccess(Hyper Text Files).
Using .htaccess, you can restrict or deny access to individual files and folders. Below is the example how to restrict or deny users from accessingimages folder. Make a .htaccess files and upload it in images folder. So this will be effective only for images folder(not for whole site).
# This will restrict all users from accessing images folder directly from web.
deny from all
If you would like to ban only one IP or range of IP than look at the below rules.







# Restrict only 192.168.0.1 IP user.
order allow,deny
deny from 192.168.0.1
allow from all
# Restrict an IP range from 192.168.0.0 to 192.168.0.10
order deny,allow
deny from 192.168.0.0/10
allow from all
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database,php info,php editor,programming php,Open-source,php help and php script , subscribe to our feed by entering email address below. You will get updates via email about every tutorial posted on this site . It will not take more than a sec.

301 Redirect old dynamic URLs to new static URLs using .htaccess




Hello Friends,
Today i faced a situation where i need to redirect dynamic URL of my shopping cart to static url. I have changed the Dynamic URL(with query string , ? and &) to static one in my sunshop shopping cart. But still if i will open dynamic url with query string than it shows the content. This is a big issue with search engine as they will consider this dynamic page and static page as two different page and duplicate content issue araise.
Redirect 301 rule in .htaccess (which is below) is common rule everybody knows.
Using .htaccess
redirect 301 http://www.domain.com/about-us.html http://www.domain.com/about.html
Using PHP
What i want is to redirect dynamic urls(with query string , ? and &) to static page. For e.g. If i want to redirect http://www.domain.com/content.php?a=1&b=2 to http://www.domain.com/content.html than look at the below htaccess rules.
RewriteCond %{HTTP_HOST} ^domain.com
RewriteCond %{QUERY_STRING} ^a=1&b=2$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/content.html [R=301,L]
Add the above three lines and change the domain name and query string as per your need. Now whenever you will enter http://www.domain.com/content.php?a=1&b=2 , it will redirect to http://www.domain.com/content.html. So now Search engine will consider both as one page and duplicate content issue will not araise.
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database,php info,php editor,programming php,Open-source,php help and php script , subscribe to our feed by entering email address below. You will get updates via email about every tutorial posted on this site . It will not take more than a sec.