Is it okay to have a very long .htaccess file?(有一个很长的 .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 文件可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有一个很长的 .htaccess 文件可以吗?
基础教程推荐
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01