动态目录和文件,如wordpress

时间:2013-12-09 20:42:50

标签: php wordpress apache

在wordpress中,有一些实际上不存在的目录。 像example.com/post/name-of-the-post实际上打开一个主php文件,从文件夹中获取该帖子的内容。 我如何在没有wordpress的linux apache php服务器上本地实现这个?

2 个答案:

答案 0 :(得分:2)

您需要use .htaccess。这是Wordpress能够做你想做的事情背后的技术。

Here are the docs from apache

Also here's a nice Tutorial

答案 1 :(得分:0)

我不知道为什么人们使用mod_rewrite,对大多数任务来说都是过度杀伤力。对于大多数事情,有更灵活的模块可用。那不是要否认mod_rewrite,它有它的位置,但我发现它已经过度使用了。在这种特殊情况下,您可以使用mod_alias,不需要mod_rewrite。 E.g。

AliasMatch ^/post/(.*) /real/path/post.php$1

模块文档:https://httpd.apache.org/docs/2.2/mod/mod_alias.html

当不使用mod_rewrite:http://httpd.apache.org/docs/current/rewrite/avoid.html

时,此文档精美地概述