可转换mod_rewrite的任何数量的参数与任何名字呢? [英] Can mod_rewrite convert any number of parameters with any names?

查看:116
本文介绍了可转换mod_rewrite的任何数量的参数与任何名字呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个总的n00b在mod_rewrite的和我想要做听起来很简单:

I'm a total n00b at mod_rewrite and what I'm trying to do sounds simple:

而不必domain.com/script.php?a=1&b=2&c=3我想有:

instead of having domain.com/script.php?a=1&b=2&c=3 I would like to have:

domain.com/script|a:1;b:2;c:3

domain.com/script|a:1;b:2;c:3

问题是,我的脚本需要大量的参数进行不同的组合,而且顺序是不重要的,所以编码每一个在EX pression并期望一定的顺序是不可行的。因此,可以在规则设置,简单地传递所有的参数给脚本,无论订单或多少参数?所以,如果有人类型

The problem is that my script takes a large number of parameters in a variety of combinations, and order is unimportant, so coding each one in the expression and expecting a certain order is unfeasible. So can a rule be set up that simply passes all of the parameters to the script, regardless of order or how many parameters? So that if someone types

domain.com/script|a:1;b:2;j:7它会通过所有这些PARAMS和值是一样的,因为它会与domain.com/script|b:2;a:1; ?

domain.com/script|a:1;b:2;j:7 it will pass all those params and values just the same as it would with domain.com/script|b:2;a:1; ?

谢谢!

推荐答案

我会用PHP解析请求的URL路径:

I would use PHP to parse the requested URL path:

$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$params = array();
foreach (explode(',', substr($_SERVER['REQUEST_URI_PATH'], 6)) as $param) {
    if (preg_match('/^([^:]+):?(.*)$/', $param, $match)) {
        $param[rawurldecode($match[1])] = rawurldecode($match[2]);
    }
}
var_dump($params);

和mod_rewrite的规则重写这些请求到你的 /script.php 文件:

And the mod_rewrite rule to rewrite such requests to your /script.php file:

RewriteRule ^script\|.+ script.php [L]

这篇关于可转换mod_rewrite的任何数量的参数与任何名字呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆