将 .htaccess 内容移动到 vhost,以提高性能 [英] Move .htaccess content into vhost, for performance

查看:40
本文介绍了将 .htaccess 内容移动到 vhost,以提高性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果我将 .htaccess 文件内容移动到 apache2 的 vhost 文件中是否可以提高性能?

I was wondering if performance can be increased if I move .htaccess file content into a vhost file of apache2?

这是我的.htaccess的内容

This is the content of my .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>

如果这样做是个好主意,我应该将 vhost 声明放在内容上方的哪个位置?

If doing so is a good idea, where in the vhost declaration should I place above content?

谢谢!

推荐答案

如果您可以编辑 vhost 配置文件,则应始终这样做..htaccess 会随着对您网站的每个请求进行解释,而另一方面,vhost.conf 仅在 httpd 重启/重新加载时进行解释.

If you have the possibility to edit vhost-configuration file(s) you should always do so. The .htaccess is getting interpreted with every single request which is made to your site while on the other hand the vhost.conf is only interpreted on httpd restart/reload.

您可以在目录指令中设置 Options - 例如:

You could set the Options in Directory-directive - e.g.:

<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>

另请查看 apache.org 上的这个 wikipost - 特别是 部分我什么时候应该使用 .htaccess 文件,我不应该使用 .htaccess 文件?

Also take a look at this wikipost on apache.org - especially the section When should I, and should I not use .htaccess files?

这篇关于将 .htaccess 内容移动到 vhost,以提高性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆