問題描述
我向網站上的人提供網址,實際上指向一些丑陋的東西(在同一個網站上).
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 文件可以嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!