【问题标题】:RewriteRule not obeyed不遵守重写规则
【发布时间】:2009-05-14 03:19:38
【问题描述】:

http://localhost/allsides/.htaccess

重写规则 (.*) index.php?$1 [L]

http://localhost/allsides/test

allsides/ 后面的一个或多个字符保存在 $1 中

$_GET 是 $1。

测试不是 $_GET!

怎么了?

【问题讨论】:

    标签: php mod-rewrite


    【解决方案1】:

    当请求…?test 时,$_GET 的第一个元素的键将是test 并且没有值(等于…?test=)。

    所以要么使用current(array_keys($_GET)) 获取$_GET 的第一个元素的键,要么使用$_SERVER['QUERY_STRING'] 获取完整查询。

    【讨论】:

    • 嗯...如何使 $_GET 成为 allsides 之后的一个或多个字符?
    • 将您的规则更改为index.php?path=$1 并查看$_GET["path"]
    • print_r($_GET);数组 ( index.php => ) (.*)/?(.*)/?(.*) index.php?controller=$1&action=$2&params=$3 print_r($_GET);数组 ( [controller] => index.php [action] => [params] => ) 怎么回事?
    • 试试这个:RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]*)/?([^/]*)/?([^/]*)$ index.php ?controller=$1&action=$2&params=$3 [L]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多