【问题标题】:PHP ( Reading URL arguments ) [closed]PHP(读取 URL 参数)[关闭]
【发布时间】:2011-11-12 21:31:46
【问题描述】:
【问题讨论】:
标签:
php
url
arguments
xampp
【解决方案1】:
相反,我认为您应该结合 PHP 的数据库功能使用 .htaccess 来引起重定向。例如:
profile.php
if (!empty($_GET['user'])) {
//Do some crazy database stuff to get the profile info or page.
}
.htaccess
重写规则 ^(.*)$ /profile.php?user=$1
(注意代码不完整,只是示例)
【解决方案2】:
简单的方法是使用 Apache 的重写规则并用 PHP 解析它。
您必须为您的 XAMPP 安装启用 mod_rewrite。
在 localhost 的根目录中创建 .htaccess,内容如下:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?uq=$1 [L,QSA]
现在,在最后一个重写规则所指的 index.php 中,您应该能够执行以下操作:
<?php
$url_parts = explode('/', $_GET['uq']);
var_dump($url_parts);
?>
PHP 转储的数组会给你一个想法。
【解决方案3】:
它使用 url 重写来使 url 看起来像那样,但通常它通过 $_GET 传递信息。所以 url 有参数和值,例如 username=example 但被重写为看起来“漂亮”。
看看mod_rewrite