Concrete5如何安排它的绝对路径?
我被要求弄清楚 Concrete5 系统如何为雇主工作,但我无法弄清楚。
我已将 Concrete5 安装到服务器上名为 /realprofessionals
的目录中。当Concrete5系统创建新页面时,它会为它们提供自己的绝对路径,例如:
http://www. wmcpartners.com/realprofessionals/footer
但是,它实际上并没有在 /realprofessionals
目录中创建一个名为 footer
的文件夹。那么它是如何运作的呢? http://www.wmcpartners.com/realprofessionals/footer 如何成为有效链接?
I've been asked to figure out how the Concrete5 system works for an employer, and I can't figure something out.
I have Concrete5 installed to a directory on the server called /realprofessionals
. When the Concrete5 system makes new pages, it gives them their own absolute paths, for instance:
http://www.wmcpartners.com/realprofessionals/footer
However, it hasn't actually made a folder in the /realprofessionals
directory called footer
. So how does that work? How can http://www.wmcpartners.com/realprofessionals/footer be a working link?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短回答:所有页面请求实际上都经过唯一的index.php 文件。页面内容存储在数据库中,而不是服务器上的文件中。
长答案:
Concrete5(以及大多数基于 PHP 的 CMS)的工作方式如下:所有请求都通过 index.php 文件路由。此路由是通过 .htaccess 文件中的一些 mod_rewrite 规则强制执行的。规则规定“对于任何请求,实际上并不转到该页面,而是转到index.php并将请求路径的其余部分作为 $_GET 参数传递”。然后在index.php代码(或index.php文件中包含的一些其他代码)中,请求的页面是根据Apache放入$_GET参数中的路径确定的(根据. htaccess),并从数据库中检索适当的内容。
与将文件存储在服务器上相比,将内容存储在数据库中具有多个优点。例如,您可以在每个页面上重复使用相同的 html 模板(页眉、页脚、侧边栏),并且如果您更改模板,它将自动反映在使用该模板的所有页面上。此外,它还可以更轻松地调整页面并为它们提供您想要的任何 URL(例如末尾没有“.php”扩展名,或 /2010/11/date/based/paths/for/blog/posts)。
当然,缺点是每个请求都需要多次数据库查询,但对于大多数站点(那些没有大量页面视图的站点)来说,这种权衡是值得的(并且各种类型的缓存可以帮助减少性能损失)。
Short answer: All page requests are actually going through the one and only index.php file. Page content is stored in the database, not in files on the server.
Long answer:
Concrete5 (and most PHP-based CMS's for that matter) work like this: all requests are routed through the index.php file. This routing is enforced with some mod_rewrite rules in the .htaccess file. The rules say "for any request, don't actually go to that page, but instead go to index.php and pass the rest of the requested path as $_GET parameters". Then in the index.php code (or some other code that is included by the index.php file), the requested page is determined based on the path that was put into the $_GET parameters by Apache (as per the mod_rewrite rule in .htaccess), and the appropriate content is retrieved from the database.
Storing content in the database as opposed to files on the server has several advantages. For example, you can re-use the same html template -- header, footer, sidebar -- on every page, and if you change the template it will automatically be reflected on all pages it's used on. Also, it makes it easier to shuffle pages around and to give them whatever URL you want (e.g. no ".php" extension at the end, or /2010/11/date/based/paths/for/blog/posts).
The disadvantage of course is that every request requires many database queries, but for most sites (those without zillions of page views), the trade-off is well worth it (and various types of caching can help reduce the performance hit).
乔丹的回答非常好,我想补充一点,您可能在网址中看不到index.php,因为您已经启用了漂亮的网址(在crete5的搜索框中输入“漂亮”检查一下)。
无论如何,以编程方式添加链接到内部页面的最佳方法是:
它既可以在本地主机上运行,也可以在线运行,无论有没有漂亮的 URL。
(对于页面名称,请转到仪表板/完整站点地图/页面名称/属性/页面路径和位置。)
Jordan's answer is excellent, I would add that you probably don't see index.php in the url because you've enabled pretty URLs (type 'pretty' on concrete5's searchbox to check that).
Anyhow, the best way to programmatically add link to internal pages is:
It works both on localhost and online, with or without pretty URLs.
(For the page-name go to dashboard/full sitemap/page-name/properties/page paths and location.)