Here is few examples how to create a redirect from using .htaccess file:
This redirect allows to redirect all requests from www.yoursite.com to yoursite.com (why it should be done? Google skip mirrored sites, for example www.yoursite.com and yoursite.com are different sites for Google, so some pages can be indexed only for www.yoursite.com and some only for yoursite.com, as a result your domain loses Google Page Rank, so you should decide which of them will be used).
Redirect from WWW to NON-WWW
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
Redirect from NON-WWW to WWW
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^yoursite\.com
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
Redirect from NON-WWW and WWW to another path
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
RewriteRule ^(.*)$ http://someurl.com/ [R=301]
There are very simple way to limit access to some your resources.
For example, you are not sure in security of your PC (probably it was or are infected by some virus, and some 3rd person can gain an access to your website). In this case you can create .htaccess file in your /admin/ folder and add following code:
Order Deny,Allow
Deny from all
Allow from XXX.XXX.XXX.XXX
Where XXX.XXX.XXX.XXX you WAN IP. If you don’t know your WAN IP it can be checked on such resources as iptools.com (it will be displayed in the top). But you can have a dynamic IP, what does it mean? It means that your ISP change IP address every few hours, so you can’t know what IP you’ll have in next few hours. In that case I advise you to deny access from all IPs (just add following code to .htaccess):
Order Deny,Allow
Deny from all
OR, you can limit access only to some important files (like database configuration file, where saved your database username and password):
<Files config.inc.php>
order allow,deny
deny from all
</Files>
or to some specific extension files:
<Files "\.(sql|tar|tar.gz|rar|zip)$">
order allow,deny
deny from all
</Files>
Also you can protect some folder by the password:
AuthName "Private zone"
AuthType Basic
AuthUserFile /home/your_username/public_html/.htpasswd
require valid-user
</Files>
or file:
<Files
config.inc.php
>
AuthName "Users zone"
AuthType Basic
AuthUserFile /home/your_username/public_html/.htpasswd
</Files>
Password is encoded in .htpasswd
so you need to generate it, you can find in Google many “htaccess passwords generator” or if you have SSH access you can generate username and password yourself:
htpasswd -c /home/your_username/public_html/.htpasswd admin