扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

怎么用PHP和htaccess获取URLs

扬州沐宇科技
2024-04-29 16:55:48
htaccess, PHP

要获取URL参数,你可以使用PHP中的$_GET$_REQUEST全局变量。例如,如果你的URL是http://example.com/index.php?page=about,你可以使用以下代码来获取page参数的值:

$page = $_GET['page'];
echo $page; // 输出为 "about"

如果你想重写URL并隐藏参数,你可以使用.htaccess文件来实现。例如,你可以将http://example.com/index.php?page=about转换为http://example.com/about。在.htaccess文件中添加以下代码:

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?page=$1 [L]

这将把http://example.com/about重写为http://example.com/index.php?page=about。然后你可以使用上面的PHP代码来获取参数的值。

扫码添加客服微信