Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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 如何将GET参数显示为新目录?_Php_Server - Fatal编程技术网

Php 如何将GET参数显示为新目录?

Php 如何将GET参数显示为新目录?,php,server,Php,Server,我目前正在一个网站上工作,学生们可以在这个网站上发表文章,其他人也可以发表评论 我已经开发了一个脚本来创建它们并将它们存储在mysql数据库中 这些文章中的每一篇都应在www.mydomain/articles/xyz下提供/ 但我不想为每个人创建一个新目录。那么,是否可以将参数article=xyz www.maydomain/articles/articles.php&articles=xyz传递给前面提到的显示 如果我的问题太复杂,我很抱歉。如果您对此有任何疑问,请随时与我联系!: 可以使

我目前正在一个网站上工作,学生们可以在这个网站上发表文章,其他人也可以发表评论

我已经开发了一个脚本来创建它们并将它们存储在mysql数据库中

这些文章中的每一篇都应在www.mydomain/articles/xyz下提供/

但我不想为每个人创建一个新目录。那么,是否可以将参数article=xyz www.maydomain/articles/articles.php&articles=xyz传递给前面提到的显示


如果我的问题太复杂,我很抱歉。如果您对此有任何疑问,请随时与我联系!:

可以使用htaccess实现,有关htaccess,请参阅本教程,本教程将为您提供指导


也许您可以使用.htaccess文件执行类似操作。 您可以将每个页面重定向到index.phppage

; /* //获得输出 大堆 [文章]=>xyz [param2]=>value2 [param3]=>value3 */ ?>
@史密斯:你需要的东西不太简单。这是完整的复制/粘贴解决方案。在根文件夹中,使用我的示例代码生成.htaccess文件,并将此php代码放在index.php页面的顶部,其中index.php和.htaccess必须位于同一根文件夹中。好的,是不是.htaccess.txt?@T.Smith htaccess是扩展名,而不是文件名,您必须创建没有文件名的文件,例如空文件名、点、扩展名。如果您是windows用户,您可以创建这样的空名称文件
<IfModule mod_rewrite.c>
    RewriteEngine On
    DirectoryIndex index.php
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule . /index.php [L]
</IfModule>
<?php

/*
Example URL
$url = www.maydomain/articles/querystring/articles/xyz/param2/value2/param3/value3
$url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
*/

$url = "www.maydomain/articles/querystring/articles/xyz/param2/value2/param3/value3";
$url = explode("/querystring/", $url);

/*
Where $url[0] is (www.maydomain/articles),
and $url[1] is the rest of it (queryqtring/articles/xyz/param2/value2/param3/value3)
*/

// If you need you can include your page articles on your index page like this
$page_name = explode("/", $url[0]);
$page_name = end($page_name);
include("/path to your directory/". $page_name .".php");

$query_string = $url[1];
// And one more explode for query string:
$query_params = explode("/", $query_string);


for($i=0; $i<count($query_params); $i++)
{
    // odd value is GET name
    $key = $query_params[$i];
    // even value is GET value
    $value = (isset($query_params[$i+1])) ? $query_params[$i+1] : "";
    $_GET[$key] = $value;
    $i++;
}

echo "<pre>";
print_r($_GET);
echo "</pre>";

/*
// GET Output
Array
(
    [articles] => xyz
    [param2] => value2
    [param3] => value3
)
*/

?>