I have test all this. Use absolute paths for everything, example:

Some quick stuff:
([a-z]+) - just small letters
([A-Z]+) - just big letters
([0-9]+) - just numbers
([a-zA-Z_-]+) - small and big letters and minus (-)
([a-zA-Z0-9_-]+) - small and big letters, numbers and minus (-)

(.*) - everything - warning!!!! don't ever use - this have to much permissions

Example 1.

www.domain.com/index.php?category=search-engine-optimization

1. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?category=$1 [R=301,L]

results: www.domain.com/search-engine-optimization

2. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)$ index.php?category=$1 [R=301,L]

results: www.domain.com/category/search-engine-optimization

3. solution
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+).html$ index.php?category=$1 [R=301,L]

results: www.domain.com/search-engine-optimization.html

4. solution
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+).html$ index.php?category=$1 [R=301,L]

results: www.domain.com/category/search-engine-optimization.html

5. solution
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)/$ index.php?category=$1 [R=301,L]

results: www.domain.com/category/search-engine-optimization/

Example 2.

www.domain.com/index.php?category=internet&subcategory=search-engine-optimization

1. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?category=$1&subcategory=$2 [R=301,L]

results: www.domain.com/internet/search-engine-optimization

2. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)/subcategory/([a-zA-Z0-9_-]+)$ index.php?category=$1&subcategory=$2 [R=301,L]

results: www.domain.com/category/internet/subcategory/search-engine-optimization

3. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ index.php?category=$1&subcategory=$2 [R=301,L]

results: www.domain.com/internet/search-engine-optimization.html

4. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)/subcategory/([a-zA-Z0-9_-]+).html$ index.php?category=$1&subcategory=$2 [R=301,L]

results: www.domain.com/category/internet/subcategory/search-engine-optimization.html

5. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)/subcategory/([a-zA-Z0-9_-]+)/$ index.php?category=$1&subcategory=$2 [R=301,L]

results: www.domain.com/category/internet/subcategory/search-engine-optimization/

Example 3.

www.domain.com/index.php?category=internet&subcategory=search-engine-optimization&more=articles

1. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?category=$1&subcategory=$2&more=$3 [R=301,L]

results: www.domain.com/internet/search-engine-optimization/articles

2. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)/subcategory/([a-zA-Z0-9_-]+)/more/([a-zA-Z0-9_-]+)$ index.php?category=$1&subcategory=$2&more=$3 [R=301,L]

results: www.domain.com/category/internet/subcategory/search-engine-optimization/more/articles

3. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ index.php?category=$1&subcategory=$2&more=$3 [R=301,L]

results: www.domain.com/internet/search-engine-optimization/articles.html

4. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)/subcategory/([a-zA-Z0-9_-]+)/more/([a-zA-Z0-9_-]+).html$ index.php?category=$1&subcategory=$2&more=$3 [R=301,L]

results: www.domain.com/category/internet/subcategory/search-engine-optimization/more/articles.html

5. solution:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)/subcategory/([a-zA-Z0-9_-]+)/more/([a-zA-Z0-9_-]+)/$ index.php?category=$1&subcategory=$2&more=$3 [R=301,L]

results: www.domain.com/category/internet/subcategory/search-engine-optimization/more/articles/

more resources:
Apache mod rewrite docs
Apache RewriteBase docs
Mod rewrite forum
Absolute and Relative paths
SEW mod rewrite tips and tricks

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

CentOS4.4/5.0下载

Posted in Linux学习笔记 at 06月 5th, 2007 / No Comments »

CentOS5.0 BT下载(CD和DVD版)
CentOS5.0 种子下载

CentOS5.0 光盘版和DVD版下载
http://mirror.linux.duke.edu/pub/centos/5.0/isos/i386/

Name Last Modified Size Type
Parent Directory/ - Directory
CentOS-5.0-i386-bin-1of6.iso 2007-Apr-10 17:12:35 625.6M application/octet-stream
CentOS-5.0-i386-bin-1to6.torrent 2007-Apr-12 05:47:10 277.7K application/x-bittorrent
CentOS-5.0-i386-bin-2of6.iso 2007-Apr-10 17:18:34 636.1M application/octet-stream
CentOS-5.0-i386-bin-3of6.iso 2007-Apr-10 17:24:21 627.5M application/octet-stream
CentOS-5.0-i386-bin-DVD.torrent 2007-Apr-11 17:34:04 277.2K application/x-bittorrent
md5sum.txt 2007-Apr-10 21:44:17 0.4K text/plain
md5sum.txt.asc 2007-Apr-12 17:41:40 0.6K text/plain
sha1sum.txt 2007-Apr-10 21:44:17 0.4K text/plain
sha1sum.txt.asc 2007-Apr-12 17:41:32 0.7K text/plain

CentOS4.4 光盘版和DVD版下载
http://mirror.linux.duke.edu/pub/centos/4.4/isos/i386/

Index of /pub/centos/4.4/isos/i386/
Name Last Modified Size Type
Parent Directory/ - Directory
CentOS-4.4-i386-LiveCD.iso 2006-Aug-19 01:32:36 688.5M application/octet-stream
CentOS-4.4-i386-LiveCD.torrent 2006-Aug-27 18:45:29 54.0K application/x-bittorrent
CentOS-4.4-i386-bin1of4.iso 2006-Aug-23 17:08:27 622.4M application/octet-stream
CentOS-4.4-i386-bin1to4.torrent 2006-Aug-27 14:44:23 173.0K application/x-bittorrent
CentOS-4.4-i386-bin2of4.iso 2006-Aug-23 17:09:40 636.2M application/octet-stream
CentOS-4.4-i386-bin3of4.iso 2006-Aug-23 17:11:01 637.5M application/octet-stream
CentOS-4.4-i386-bin4of4.iso 2006-Aug-23 17:11:34 312.8M application/octet-stream
CentOS-4.4-i386-binDVD.torrent 2006-Aug-27 14:40:30 172.7K application/x-bittorrent
CentOS-4.4.ServerCD-i386.iso 2006-Sep-15 21:32:51 579.8M application/octet-stream
Readme.txt 2006-May-05 21:35:17 3.3K text/plain
md5sum 2006-Aug-27 17:47:20 0.3K application/octet-stream
md5sum.asc 2006-Aug-27 17:49:35 0.5K text/plain
md5sum.livecd 2006-Aug-27 18:12:27 0.1K application/octet-stream
md5sum.livecd.asc 2006-Aug-27 19:14:59 0.2K text/plain
md5sum.servercd 2006-Sep-27 08:04:30 0.1K application/octet-stream