重写虚拟主机或 .htaccess 中的条件和规则?哪个是首选?
Rewrite conditions and rules in Virtual host or .htaccess? Which is preferred?
我正在使用 apache 2.4
并托管一个 angular2
应用程序。我已经在我的虚拟主机中编写了 rewrite rules and conditions
,但我想知道我是否应该使用 .htaccess
文件。使用一个比另一个有什么好处?
Edit: Added .htaccess
我尝试为 angular2 实施 .htaccess
,看来我必须手动将 .htaccess
粘贴到 dist
文件夹中。这会很糟糕。但是,我仍然要求这是一个通用的应用程序。应该首选哪种配置?做virtual host
里的配置还是有单独的.htaccess
?
我看过这个apache documentation,这几乎消除了我的困惑。
如果不需要经常更改rewrite configurations
,文档建议不要使用.htaccess
。
可能需要更改这些,例如:
.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. In the event that the server administrator is not willing to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves. This is particularly true, for example, in cases where ISPs are hosting multiple user sites on a single machine, and want their users to be able to alter their configuration.
为什么不用?
The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, httpd will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.
In the case of RewriteRule directives, in .htaccess context these
regular expressions must be re-compiled with every request to the
directory, whereas in main server configuration context they are
compiled once and cached.
我正在使用 apache 2.4
并托管一个 angular2
应用程序。我已经在我的虚拟主机中编写了 rewrite rules and conditions
,但我想知道我是否应该使用 .htaccess
文件。使用一个比另一个有什么好处?
Edit: Added .htaccess
我尝试为 angular2 实施 .htaccess
,看来我必须手动将 .htaccess
粘贴到 dist
文件夹中。这会很糟糕。但是,我仍然要求这是一个通用的应用程序。应该首选哪种配置?做virtual host
里的配置还是有单独的.htaccess
?
我看过这个apache documentation,这几乎消除了我的困惑。
如果不需要经常更改rewrite configurations
,文档建议不要使用.htaccess
。
可能需要更改这些,例如:
.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. In the event that the server administrator is not willing to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves. This is particularly true, for example, in cases where ISPs are hosting multiple user sites on a single machine, and want their users to be able to alter their configuration.
为什么不用?
The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, httpd will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.
In the case of RewriteRule directives, in .htaccess context these regular expressions must be re-compiled with every request to the directory, whereas in main server configuration context they are compiled once and cached.