关于这个htaccess文件的四个具体问题

时间:2011-03-11 20:19:24

标签: zend-framework .htaccess

#+FollowSymLinks must be enabled for any rules to work, this is a security 
#requirement of the rewrite engine. Normally it's enabled in the root and you 
#shouldn't have to add it, but it doesn't hurt to do so.
Options +FollowSymlinks
#Apache scans all incoming URL requests, checks for matches in our .htaccess file 
#and rewrites those matching URLs to whatever we specify.
#to enable runtime rewriting engine
RewriteEngine On

#this tells mod_rewrite to leave the URL unchanged (the dash part -) and quit 
#other rewwrite processing rules if the requested segment has one of those 
#prefixes (that's what we asking when we use the ^ sign), on the list. If the 
#prefix is in the list, all subsequent Rewrite Rules are skipped.
#So to avoid some files OR directories to be redirected we use:
RewriteRule ^(somefile|somedir|someotherfile) – [L]

1)在我们之前的RewriteRule之前,我们不需要这样的条件吗?

#this will allow direct linkage to this extensions, regardless the case sensitive.
RewriteCond %{REQUEST_FILENAME} !\.(js|ico|zip|rar|mov|mpeg4|mp4|gif|jpg|png|css|doc|pdf|docx|wmv|mpeg|avi|mpg|flv|ppt|pptx|txt)$ - [NC]

2)[NC]标志是否会处理所有案例变化?

#if the request uri has not public...
RewriteCond %{REQUEST_URI} !^/public/.*$
#rewrite to public something...
RewriteRule ^(.*)$ /public/$1

3)为什么我们的RewriteRule上有$ 1而不是/public/index.php?

#rewrite all requests that start with public, to public/index.php and if that's 
#the case, don't run any other rule.
RewriteRule ^public/.*$ /public/index.php [NC,L]

4)因为这是最后一条规则,我们可以删除L标志吗?

1 个答案:

答案 0 :(得分:1)

  1. 不,任何以somefilesomedirsomeotherfile开头的内容都不会被重写(-)。 [L]确保不会处理其他规则(包括此规则)。
  2. 因为RewriteCond也可以匹配/public/otherthing,而不仅仅是/public/index.php
  3. 不,如果没有[L],则会发生无限循环,因为重写的网址/public/index.php`^public.*$匹配。
相关问题