简单定向
will never match, because the incoming URL never has a leading slash in directory context. This is explained in detail in the Apache documentation, see the resource links.
Troubleshooting
定义错误页面
Pre-built “magic” error pages
There are some “magic” error pages settings which could be problematic when you want to use rewrite rules. The most simple solution: turn off them!
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default
No input file specified
When using http://site.com/query1/query2/ type of URLs that rewrite to http://site.com/index.php/query1/query2/ with mod_rewrite and PHP you might get a “No input file specified” error. There is a simple workaround, and it is to add a question mark to the the .htaccess right after the file you want to send the query strings to, as such:
将不存在的文件和目录定向到index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
That forces Apache to consider everything after index.php as a query string. This is known to fix broken pretty URLs for MediaWiki, CodeIgniter, ExpressionEngine and a few other major scripts.
If this still doesn’t work, you might be using FastCGI. Go into Domains > Manage Domains in your panel. Click the Edit wrench under Web Hosting for the domain you’re working with. Change “FastCGI” to just “CGI”. Save changes and it should work.
The FastCGI version when paired with Apache 2.2 doesn’t seem to like the rewriterule index.php/$1. Instead it prefers index.php?$1 but some CMS don’t like that.
/stats no longer works
Some 3rd party apps like WordPress, Drupal will take over your directory structure to give you a nice clean url but in the process break your /stats pages.
The Wiki page on how to deal with this is Making stats accessible with htaccess.
# Quick Fix:
RewriteRule . - [L]
For Drupal:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(stats/|missing\.html|failed_auth\.html) [NC]
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
For Mambo:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(stats/|missing\.html|failed_auth\.html) [NC]
RewriteRule . /index.php [L]
For WordPress:
# You should place these lines outside the (begin|end) WordPress block
# or they may get removed.
RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html) [NC]
RewriteRule . - [L]
# Original WordPress rules. Leave these alone.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
For Typo:
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(stats/|missing\.html|failed_auth\.html) [NC]
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
For Trac:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(stats/|missing\.html|failed_auth\.html) [NC]
RewriteRule ^(.*)$ /trac.fcgi/$1 [L,QSA]
RewriteRule ^$ trac.fcgi [L]
For Kohana:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php) [NC]
RewriteRule ^(.*)$ /index.php?kohana_uri=$1 [PT,L]
For MediaWiki
This depends on how you install Mediawiki and whether you use mod_rewrite to get clean URLs. If you install it correctly, /stats will not be broken. See the alternate simpler method of getting clean URLs for install instructions that do not break /stats.
For DokuWiki
This is my own modification, it is not ideal surely, but it’s work.
.htaccess file:
RewriteBase /dokuwiki
RewriteRule ^/?_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
RewriteRule ^/?_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
RewriteRule ^/?_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L]
RewriteRule ^$ doku.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(stats/|missing\.html|failed_auth\.html) [NC]
RewriteRule (.*) doku.php?id=$1 [QSA,L]
RewriteRule ^/?index\.php$ doku.php
They were added only two lines to standard .htaccess file
RewriteCond %{REQUEST_URI} !^/(stats/|missing\.html|failed_auth\.html) [NC]




不懂,呵呵。