【问题标题】:How do I rewrite an URL to an PHP array using mod_rewrite?如何使用 mod_rewrite 将 URL 重写为 PHP 数组?
【发布时间】:2019-03-09 13:08:59
【问题描述】:

我不知道如何从以下表单重写 URL(使用 mod_rewrite)

https://example.com/foo/bar/123/asd/qwerty

到下面的表格

https://example.com/index.php?controller=foo&action=bar&params[]=123&params[]=asd&params[]=qwerty

总会提供控制器和动作,但之后的参数数量可能会有所不同。我目前正在将整个 123/asd/qwerty 作为字符串传递给 PHP 中的 $_GET['params'],但我现在想将此字符串转换为已经拆分的数组。

我使用什么 RewriteRule?

【问题讨论】:

标签: php apache .htaccess mod-rewrite


【解决方案1】:

我不确定您需要的是重写规则。 mod_rewrite 正在做什么,应用时从
A: https://example.com/foo/bar/123/asd/qwerty乙: https://example.com/index.php?controller=foo&action=bar&params[]=123&params[]=asd&params[]=qwerty

但是:在上述情况下,B 是原始 URL,而 A 是重新编写的……这对用户更友好。由于您没有在 URL 中传递变量,因此您无法从中“获取”它。我认为唯一的方法是获取 url 并使用 php 将其分成几部分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2011-09-29
    • 2011-11-10
    相关资源
    最近更新 更多