2011-05-22 113 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文件?

相关问题