2011-05-22 27 views
16

我想知道如果將.htaccess文件內容移動到apache2的虛擬主機文件中,性能是否會增加?將.htaccess內容移到虛擬主機中,以獲得性能

這是我的.htaccess

Options +FollowSymLinks +ExecCGI 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC] 
    RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L] 

    # we check if the .html version is here (caching) 
    RewriteRule ^$ index.html [QSA] 
    RewriteRule ^([^.]+)$ $1.html [QSA] 
    RewriteCond %{REQUEST_FILENAME} !-f 

    # no, so we redirect to our front web controller 
    RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule> 

如果這樣做是一個好主意,其中虛擬主機聲明我應該將上述內容的內容?

謝謝!

回答

10

如果您有編輯虛擬主機配置文件的可能性,您應該始終這樣做。 .htaccess正在被解釋爲每個請求都會發送到您的站點,而另一方面,vhost.conf僅在httpd restart/reload上解釋。

您可以設置目錄的指令的Options - 如: - 當要我,而且我不應該使用的.htaccess尤其是部分

<Directory /usr/local/apache2/htdocs/somedir> 
Options +FollowSymLinks +ExecCGI 
</Directory> 

<VirtualHost [...]> 
[...] 
RewriteEngine On 

RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC] 
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L] 

# we check if the .html version is here (caching) 
RewriteRule ^$ index.html [QSA] 
RewriteRule ^([^.]+)$ $1.html [QSA] 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f 

# no, so we redirect to our front web controller 
RewriteRule ^(.*)$ index.php [QSA,L] 
</VirtualHost> 

也看看這個wikipost上apache.org文件?