Below I show some common uses of .htaccess which I use myself on many sites. Many of you will find no new information here, but hopefully it will help some!
Code:
Options -Indexes

This causes the server not to list the contents of directories (when there is no index). This keeps people from typing in http://www.example.com/images/ (or any other directory) and getting a list of the files.
Code:
AddType application/x-httpd-php .php .htm

This code tells your server to process PHP code in files with the .htm extension. Some servers allready do this by default, but many do not. You can also add .html to the end (or any other extension) if you like. This will keep you from having to rename files to php if you add scripts in later, and also I just happen to like it more
Code:
ErrorDocument 400 /errors/400.htm
ErrorDocument 401 /errors/401.htm
ErrorDocument 403 /errors/403.htm
ErrorDocument 404 /errors/404.htm
ErrorDocument 500 /errors/500.htm


The control panel of many hosts let you set the custom error pages, but doing it directly is just as easy. I use these 5 common ones. Just create your pretty error pages, and point to them in .htaccess.
Code:
redirectPermanent /somepage.htm http://www.example.com/index.htm

Just a basic redirect example here. For when you get rid of a page and want all links to it to just point to the index.
Code:
redirectMatch 301 ^/old_directory/(.*) http://www.example.com/index.htm

Here we get a little fancier. This is for when you remove an entire directory. It will make any link to that directory (including all pages and sub-pages in it) go back to your main index.
Code:
redirectMatch 301 ^/subsite/(.*) http://www.example.com/$1
redirectMatch 301 ^/subsite http://www.example.com/$1

Say you have a sub-site on your domain.. in the 'subsite' directory, and you moved it to its own domain. These two redirects will take all possible link combinations and redirect them to the new domain. Even if the link is like this : /subsite/1/2/3/4/index.php it will redirect to www.example.com/1/2/3/4/index.php. The two lines give you better flexibility. It handles all combinations of trailing slashes, directories/files, and www. prefixes.
Code:
Options +FollowSymLinks
RewriteEngine on

This code gets the server ready for the next few things we will do
Code:
RewriteCond %{HTTP_HOST} ^example.(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

This bit of code is quite usefull. It will take any links that do not have www in them, and add it to the URL. This means no matter how they link to you, your full domain (with the www) will get the backlink.
Code:
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.example.com/index.htm [R,NC]

This is basic hot-link protection code. I did have two other lines added to it (to take care of the times when the link does not contain the www) but if you use the last tip, you do not have to worry about it. Just make sure to put them in order (so the www gets added before the hot-link protection). This will only allow hot-linking from your site. If you want to add another site, just add the appropriate lines.

Now if you want to sometimes allow hot-linking, here is a good method. Create a directory called 'share' (or whatever) and stick in a new .htaccess file with only this line:
Code:
RewriteEngine off

This will counter-act the global .htaccess, and allow hot-linking from whatever directory you stick it in (and sub-directories)

0

测试Google的限制访问

Posted in SEO at 05月 3rd, 2007 / No Comments »

在输入不良或者有害的查询信息后Google.cn会限制用户的访问。这个早有耳闻。曾经一段时间自己的google.com无法访问,当时就是怀疑整个网段被google封杀,不得以改了本机DNS才了事。

还有一次朋友搜索一些黑客木马相关关键字,也被Google迅速封杀,暂时无法使用搜索功能。今天我又遇到一次,采用了一个自动查询关键字排名的小软件,因为连续查询几次,导致Google对我限制了使用搜索功能。下面是提示信息:

很抱歉..
... 此刻我们无法回应您的要求。该请求通过电脑病毒或间谍软件向我们自动发送,而且看来您的电脑或网络已受感染。

我们会尽快恢复您的使用,请稍后再试。同时,您可以运行病毒检测器或间谍软件清除器确保您的电脑没有携带病毒及其它欺诈软件。

我们对此深感抱歉,希望很快在Google 与您再会。
  如要继续,请输入下列字符:

Google的限制访问

这个问题在输入验证码后就能得到解决。但是不知道更加严重情况下会不会遭到Google对IP的长期封杀?