Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 复杂的URL重写(无顺序)_Php_.htaccess_Url Rewriting - Fatal编程技术网

Php 复杂的URL重写(无顺序)

Php 复杂的URL重写(无顺序),php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我必须重写一个复杂的URL,它可以包含0到20个不同的参数。 问题在于参数的顺序未定义,这取决于用户如何使用站点 例如,我可以: www.site.com/page.php?A=x&B=x OR www.site.com/page.php?B=x&A=x 我希望这些url被重写为一个独特的url,如: www.site.com/A-B.html 有没有办法重写这样的东西? 谢谢您是的,具有加入功能: $params = array(); foreach ($_GET as $

我必须重写一个复杂的URL,它可以包含0到20个不同的参数。 问题在于参数的顺序未定义,这取决于用户如何使用站点

例如,我可以:

www.site.com/page.php?A=x&B=x OR
www.site.com/page.php?B=x&A=x
我希望这些url被重写为一个独特的url,如:

www.site.com/A-B.html
有没有办法重写这样的东西?
谢谢您

是的,具有加入功能:

$params = array();
foreach ($_GET as $key => $val) {
    $params[] = $key;
}
if (count($params)) {
    header("Location: " . join("-", $params) . ".html");
    die();
}

您可以尝试使用.htaccess:

RewriteEngine on 

RewriteCond %{REQUEST_URI} ^/page\.php
RewriteCond %{QUERY_STRING} A=
RewriteCond %{QUERY_STRING} B=
RewriteRule .* A-B.html [QSA,L]

只有当你对a=&b=etc的内容感兴趣时才使用[QSA]。

U是指.htaccess规则还是只使用编程语言?好吧,所有可能有效的规则,我只想在谷歌上正确显示我的URL!我对A和B的内容感兴趣,它是否有用?是的,像A-B.html一样?B=x&A=xOk,我能像A-x-B-x.html一样重写它吗?不需要上面的。htaccess,这是可能的,但如果A&B订单发生变化,就不那么容易了……是的,我是这么想的,不管怎样,我会用你给我的东西做