gpt4 book ai didi

.htaccess - 将 .htaccess 内容移至虚拟主机以提高性能

转载 作者:行者123 更新时间:2023-12-02 21:35:23 25 4
gpt4 key购买 nike

我想知道如果我将.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>

如果这样做是个好主意,我应该将内容放在虚拟主机声明中的什么位置?

谢谢!

最佳答案

如果您可以编辑虚拟主机配置文件,您应该始终这样做。 .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>

也看看这个wikipost在 apache.org 上 - 特别是 我应该什么时候使用 .htaccess 文件?

关于.htaccess - 将 .htaccess 内容移至虚拟主机以提高性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6085222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com