Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将.htaccess内容移动到vhost中以提高性能_.htaccess_Apache2_Vhosts - Fatal编程技术网

将.htaccess内容移动到vhost中以提高性能

将.htaccess内容移动到vhost中以提高性能,.htaccess,apache2,vhosts,.htaccess,Apache2,Vhosts,我想知道如果我将.htaccess文件内容移动到apache2的vhost文件中,是否可以提高性能 这是my.htaccess的内容 Options +FollowSymLinks +ExecCGI <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC] RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

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

这是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>
Options+FollowSymLinks+ExecCGI
重新启动发动机
重写条件%{SERVER\u NAME}^([^.]+\.[^.]+)$[NC]
重写规则^(.*)$http://www.%1/$1[R=301,L]
#我们检查.html版本是否在这里(缓存)
重写规则^$index.html[QSA]
重写规则^([^.]+)$$1.html[QSA]
重写cond%{REQUEST_FILENAME}-F
#不,所以我们重定向到前端web控制器
重写规则^(.*)$index.php[QSA,L]
如果这样做是一个好主意,那么我应该在vhost声明中将上述内容放在哪里


谢谢

如果您可以编辑vhost配置文件,您应该始终这样做。.htaccess会随着向站点发出的每个请求而被解释,而vhost.conf只会在httpd重新启动/重新加载时被解释

您可以在目录指令中设置
选项
,例如:

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

选项+FollowSymLinks+ExecCGI
[...]
重新启动发动机
重写条件%{SERVER\u NAME}^([^.]+\.[^.]+)$[NC]
重写规则^(.*)$http://www.%1/$1[R=301,L]
#我们检查.html版本是否在这里(缓存)
重写规则^$index.html[QSA]
重写规则^([^.]+)$$1.html[QSA]
重写cond%{DOCUMENT\u ROOT}%{REQUEST\u FILENAME}-F
#不,所以我们重定向到前端web控制器
重写规则^(.*)$index.php[QSA,L]
在apache.org上也可以看到这一点,特别是我应该在什么时候使用,不应该使用.htaccess文件