有一个很长的 .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 文件可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Break HTTP file uploading from server side by PHP or Apache(通过 PHP 或 Apache 从服务器端上传 HTTP 文件)