.htaccess 或 httpd.conf
我现在需要做一个 url 重写工作。
我不知道是否应该将代码放入 .htaccess 或 httpd.conf 中?
编辑
.htaccess 的影响范围是多少?它会影响所有请求还是仅影响对其所在特定目录的请求?
I need to do a url-rewriting job now.
I don't know whether I should put the code into a .htaccess or httpd.conf?
EDIT
What's the effecting range of .htaccess?Will it affect all requests or only requests to the specific directory it's located?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您不需要经常更改规则,则应该将它们放在 httpd.conf 中,并在规则适用的顶级目录中关闭覆盖。
如果没有覆盖,您的 apache 将不会扫描每个目录中的 .htaccess 文件,从而减少每个请求的开销。
每当您确实需要更改规则时,如果您将其放入 httpd.conf 中,则必须重新启动 apache 服务器,而不是在 .htaccess 文件中立即检测到它们,因为它会在每个请求时读取所有规则。
您可以使用 apachectl 工具正常重启来轻松完成此操作,以避免切断任何当前正在服务的请求。
如果您不打算关闭覆盖,您不妨只使用 .htaccess。
根据您的编辑进行编辑:
假设您有一个对 www.example.com/dir1/dir2/dir3/file 的请求,
Apache 将在所有 3 个目录和根目录中查找 .htaccess 文件如果您允许覆盖,则适用于该请求的规则。
If you wont have to change your rules very often, you should put them in the httpd.conf and turn off overriding in the top directory your rules apply to
With no overriding, your apache will not scan every directory for .htaccess files making less of an overhead for each request.
Whenever you do have to change your rules, you will have to restart your apache server if you put it in your httpd.conf as opposed to them being instantly detected in .htaccess files because it reads them all on every request.
You can easily do this using a graceful restart with the apachectl tool to avoid cutting off any current requests being served.
If you aren't going to turn override off, you might as well just use .htaccess only.
Edit in response to your edit:
Say you have a request for www.example.com/dir1/dir2/dir3/file
Apache will look for a .htaccess file in all 3 of those directories and the root for rules to apply to the request if you have overriding allowed.
易于使用和 IMO 可维护性(只需作为任何许可用户转到您想要的目录)=
.htaccess
但会重复解析,而不是在httpd.conf
中解析一次最适合设置超高音量的位置。Ease of use and IMO maintainability (just go to the dir you want as any permissioned user) =
.htaccess
but that is parsed repeatedly vs. the parse once inhttpd.conf
where your über-high volume would be best set.这里存在三个问题,就哪个“更好”而言:
.htaccess 速度较慢、难以管理且安全性可能较差。如果您有权访问 httpd.conf,那么将规则放置在那里可以更容易管理(在一个地方)、更快(“AllowOverrides None”意味着服务器不会在当前目录和任何父目录中查找覆盖文件来解析和遵循),并且由于 .htaccess 文件不存在于网站目录中,因此无法编辑它们(如果创建,将被忽略)。
There are three issues here in terms of which is "better":
.htaccess is slower, harder to manage, and potentially less secure. If you have access to the httpd.conf, then placing rules there can be easier to manage (in one place), faster ("AllowOverrides None" means that the server does not look in the current directory and any parent directories for an override file to parse and follow), and since .htaccess files are not present in the website directory, they cannot be edited (and if created, will be ignored).
您可以同时使用它们。恕我直言,.htaccess 会好一点
You may use both of them. IMHO, .htaccess will be a bit better