怎么用PHP和htaccess获取URLs

   2024-10-20 4780
核心提示:要获取URL参数,你可以使用PHP中的$_GET或$_REQUEST全局变量。例如,如果你的URL是http://example.com/index.php?page=about,你

要获取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 OnRewriteRule ^([^/]*)$ /index.php?page=$1 [L]

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

 
举报打赏
 
更多>同类网点查询
推荐图文
推荐网点查询
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号