有一个很长的 .htaccess 文件可以吗?

Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)
本文介绍了有一个很长的 .htaccess 文件可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我向网站上的人提供网址,实际上指向一些丑陋的东西(在同一个网站上).

I am giving out URLs to people on a website, that actually point to something ugly (on the same website).

http://www.mydomain.com/cool-URL
实际上指向
http://www.mydomain.com/boring.php?id=478547&sessid=34734asdf7&otherboringdetails

我计划在需要时通过修改 .htaccess 文件来实现这一点.我将让 PHP 脚本写入 .htaccess 文件,每当有新的 url 分发时添加一个新的重写规则(非程序员可以控制的管理区域[为此指定 URL 标题)新条目,管理员:它将自动分配]).

I'm planning to achieve this by modifying the .htaccess file whenever needed. I'm going to make the PHP script write to the .htaccess file, adding a new rewrite rule whenever there is a new hand-out of a url (from an admin area a non-programmer can control [specify the URL title for this new entry, admin : it will be assigned automagically]).

这是否会成为问题,尤其是在 1000 个左右的此类 URL 之后?可接受的实际数字是多少?因为,我可以想象:服务器收到一个 URL 请求,然后它在 .htaccess 文件中搜索这个 url 的正确页面,最后将用户发送到正确的页面.如果这类似于数据库搜索,用户可能需要很长时间才能真正到达正确的页面...

Is this going to be a problem, especially after 1000 or so such URLs? What is the actual number that is acceptable? Because, I can picture this: the server receives a request for a URL, then it searches the .htaccess file for the right page for this url, and finally sends the user to the right page. If this is anything like Database searching, it might take a long time for the user to actually get to the right page...

请指点一下?

推荐答案

不,这不行,而且会妨碍您的页面加载速度.

.htaccess 文件根据每个服务器请求进行评估.即使对于静态图像、CSS 和 JS 文件.因此,您要求网络服务器在执行请求时解析 1000 多行可能是 REGEX 行.

.htaccess files are evaluated on EVERY server request. Even for static images, CSS and JS files. So, you're asking the webserver to parse 1000+ long possibly REGEX lines while executing a request.

此外,父目录的 .htaccess 文件也会针对子目录中的文件进行处理.因此,如果您的大 .htaccess 位于网站的根目录中,那么它也会针对子目录中的文件(以及子目录中的 .htaccess 文件)发出的所有请求进行处理.

Also, parent directory's .htaccess file is processed for files residing in subdirectory too. So, if your large .htaccess is in root directory of website, then it will be processed for all requests made for files in the subdirectories too (along with the .htaccess file in subdirectory).

那个我的朋友正在处理很多.如果您有一个包含 10 个图像的页面(例如),它会处理 11 次.文件中的处理越多,所需的周期就越多.所以是的,htaccess 文件中的任何内容都会产生影响.现在这种影响明显吗?很难说它何时成为问题.但是它必须非常大,因为处理相对简单,在您的情况下就是这样.

That my friend is a lot of processing. If you have a page with 10 images (for example) it gets processes 11 times. And the more processing in the file, then the more cycles it takes. So yes, anything in a htaccess file has an impact. Now is that impact noticeable? It is hard to say when it becomes an issue. But it would have to be pretty big as the processing in relatively simple, which in your case is.

htaccess 文件的关键是让它变得智能.您不想列出 200 个条目.只需几行就可以让它变得聪明(如果你想使用 htaccess).

The key with an htaccess file is to make it smart. You would not want to list 200 entries. You can so it smart with just a few lines (if you want to use htaccess).

这篇关于有一个很长的 .htaccess 文件可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)