【问题标题】:best way to process unlimited subfloders via query string (php)通过查询字符串 (php) 处理无限 subfloders 的最佳方法
【发布时间】: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


    【解决方案1】:

    你这样做的方式很不安全,但是如果你 urlencode pages/example/test/test2 你可以在查询字符串中使用它:

    mydomain.com/pages%2Fexample%2Ftest%2Ftest2
    

    【讨论】:

    • 谢谢!但是 - .htaccess 文件看起来如何呢?为什么这不安全? (哦:如果我最终获得 15 个声望,我会投票 ^^)
    猜你喜欢
    • 1970-01-01
    • 2019-03-02
    • 2012-05-31
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    相关资源
    最近更新 更多