2011-03-11 20 views
0
#+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之前有一個條件嗎?關於這個htaccess文件的四個具體問題

#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)爲什麼我們有$ 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位?

+0

對於問題1,2和4 a是或否就足夠了。 :) – MEM 2011-03-11 20:33:01

回答

1
  1. 沒有,任何與somefilesomedirsomeotherfile開始將不被改寫(-)。 [L]確保進一步的規則(包括這一個)不會被處理。
  2. 是的。
  3. 因爲RewriteCond也可以匹配/public/otherthing,而不僅僅是/public/index.php
  4. 不,沒有[L],將發生無限循環,因爲重寫的URL /public/index.php匹配`^public.*$
+0

我可以問你的意見,如果這個.htaccess文件有一些我需要考慮的嚴重問題?或者是否有任何標準方法可以做到我可能不知道的上述內容?提前致謝。 – MEM 2011-03-11 21:05:22

+0

將'[L]'添加到您的關於靜態文件的規則中,這些URL不必重寫。 'RewriteRule模式-'只是意味着「保留當前的URL,尋找更多的規則」。附加'[L]'表示「保留當前URL並且不搜索進一步的重寫」。 – Lekensteyn 2011-03-11 21:12:20