Dav*_*idW 16 .htaccess apache2 vhosts
我想知道如果我将.htaccess文件内容移动到apache2的vhost文件中是否可以提高性能?
这是我的.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>
Run Code Online (Sandbox Code Playgroud)
如果这样做是个好主意,我应该在vhost声明中放置哪些内容?
谢谢!
Sey*_*sen 12
如果您有可能编辑vhost配置文件,则应始终这样做..htaccess将被解释为对您的站点发出的每个请求,而另一方面,vhost.conf仅在httpd restart/reload上解释.
您可以Options在Directory-directive中设置 - 例如:
<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>
Run Code Online (Sandbox Code Playgroud)
另请参阅 apache.org 上的这个wikipost - 特别是我应该什么时候,我应该不使用.htaccess文件?