解释这个.htaccess片段

Chr*_*ris 2 regex .htaccess

有人可以解释下面的htacess行,我理解部分,但想要更深入的知识.作为一个注释,我假设它按预期工作,这不是现在的,我只是阅读一些工作簿,这是打印.

// Don't understand this line 
Options -Multiviews 

// Don't understand this line
Options +FollowSymLinks

// Understand this line
RewriteEngine On

// Don't ~fully~ understand this line, esp. in context
RewriteBase /portfolio

// Don't ~fully~ understand this line
// I understand that its asking if the filename is a valid file or dir
// but is it overall saying if valid file or valid dir perform rewrite?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

// Don't understand, $1 is the STRING, and the rest the condition, but
// how do you read this condition?
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

// Don't understand (but do understand the RewriteRule PATTERN REPLACE, but is it
// saying replace 'all' with index.php/all ?
RewriteRule ^(.*)$ index.php?/$1
Run Code Online (Sandbox Code Playgroud)

Rii*_*imu 5

Options -Multiviews 
Run Code Online (Sandbox Code Playgroud)

这会禁用Multiviews Apache选项.基本上,该选项允许服务器根据客户端接受的内容类型和语言,使用不同的文件名在同一目录中查找内容.在这种情况下,该指令仅被禁用,以确保Apache不提供任何意外文件.

Multiviews支持内容协商,详情请参阅:http://httpd.apache.org/docs/current/content-negotiation.html

Options +FollowSymLinks
Run Code Online (Sandbox Code Playgroud)

这可确保启用FollowSymLinks选项.此设置允许Apache跟踪目录中的符号文件链接(如果存在).如果存在符号文件链接以使文件实际存在于服务器上的其他位置而不是请求,则存在此设置.

更长的解释:http://www.maxi-pedia.com/FollowSymLinks

RewriteBase /portfolio
Run Code Online (Sandbox Code Playgroud)

此设置用于定义重写引擎使用的URL的基本路径.当重写引擎重写.htaccess中的url时,它会删除当前目录的路径.一旦url重写完成,它将根据当前文件目录将其添加回来.但是,有时请求的URL与服务器本身上的目录结构没有相同的路径.RewriteBase告诉rewritengine当前目录的URL路径是什么.在这种情况下,例如,可以存储文件/foo/bar,但是可以通过浏览器访问它们www.example.com/portfolio.RewriteBase告诉引擎添加/portfolio到url,而不是/foo/bar.

有关完整说明,请参阅:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase(该URL还包含对.htaccess的其他重写部分的说明).

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Run Code Online (Sandbox Code Playgroud)

这些行确保任何实际存在的文件或目录的URL都不会被重写.该!条件之前是否定.所以这两个条件应该理解为ifNotFile AND ifNotDirectory.

RewriteCond $1 !^(index\.php|images|robots\.txt|css)
Run Code Online (Sandbox Code Playgroud)

$1这里指的是实际的重写的子模式捕获1.换句话说,它表示(.*)在RewriteRule中捕获的部分.基本上,这个规则只是检查RewriteRule不会重写任何以"index.php","images","robots.txt"或"css"开头的url.

RewriteRule ^(.*)$ index.php?/$1
Run Code Online (Sandbox Code Playgroud)

这只是告诉重写引擎任何请求(当然不是由重写条件阻止)都应该index.php?用它后面的实际请求重写.就像你说的那样,请求foo/bar将转发给index.php?foo/bar.关键是允许index.php处理文件请求(可以通过它访问它们$_SERVER['QUERY_STRING']),这在CMS系统和框架中是非常常见的做法.

我希望这些解释会有所帮助.我对所有这些指令没有丰富的经验,因此可能存在轻微的不准确之处,如果有,请发表评论.