【发布时间】:2014-02-18 18:01:09
【问题描述】:
我编写了一个动态加载内容的 php 脚本。我的意思是:当您访问 mydomain.com/example 时,它会被 htaccess 重写(真正的 url 类似于 mydomain.com/index.php?example)并根据查询字符串加载内容。
$page = $_SERVER['QUERY_STRING'];
if (file_exists("pages/".$page.".txt") ) {
load the file and so on
}
但同时支持子文件夹的最佳解决方案是什么?这样你就可以进入 mydomain.com/example/test/test2 并从 pages/example/test/test2 中获取内容?我想这应该包含在查询字符串中,但使用 .htaccess 重写。 目前,我的 htaccess 看起来像这样:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1 [L]
【问题讨论】:
标签: php .htaccess query-string