Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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转换为一组GET参数_Php_Url_Parameters_Get - Fatal编程技术网

Php 将url转换为一组GET参数

Php 将url转换为一组GET参数,php,url,parameters,get,Php,Url,Parameters,Get,我想将带有参数的url转换为路径,即 http://www.example.com/?page=1 => http://www.example.com/1 http://www.example.com/?section=books&category=thriller&page=1 => http://www.example.com/books/thriller/1 然后我希望能够得到所有这些参数,以便在查询中使用它们,以便根据这些参数进行选择,我不知道从哪里开始,我

我想将带有参数的url转换为路径,即

http://www.example.com/?page=1 => http://www.example.com/1
http://www.example.com/?section=books&category=thriller&page=1 => http://www.example.com/books/thriller/1
然后我希望能够得到所有这些参数,以便在查询中使用它们,以便根据这些参数进行选择,我不知道从哪里开始,我该如何做?我使用这个.htaccess将所有请求重定向到index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

如何将路径“转换”为一组参数以在查询中使用它们?

您可以将其向后转换。您希望用户以
http://www.example.com/books/thriller/1
,然后将其重写为
index.php?qs=$1
,供php处理。这样,用户可以看到“友好的”URL,PHP可以看到对其友好的格式

因此,您的重写规则将更改为:

RewriteRule ^(.*)$ index.php?qs=$1 [QSA,L]
然后,您可以通过以下方式访问其内容:

$myQueryVars = explode('/', $_GET['qs']);
http://www.example.com/books/thriller/1
变为

array( 'books', 'thriller', '1' )

我会做这样的事

RewriteRule ^([0-9]+)$ index.php?page=$1
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9]+)$ index.php?section=$1&category=$2&page=$3

问题是什么?你的重定向不起作用?您的php脚本没有正确处理请求?它写着:“我希望能够从路径中提取参数,能够用它们查询数据库”您的问题不清楚,您问了一些问题,然后又问了一些相反的问题。这似乎是可行的,但如果用户添加了一些参数,我该怎么办?i、 e.
http://www.example.com/books/thriller/1?a=234
@Harlandraka然后你将拥有
$\u GET['qs']
以及
$\u GET['a']