如何解决从URI获取激活密钥字符串
我有以下格式的URL:
https://www.example.com/activate/9ajebaidblahdeblahblah2020
我的设置是/activate/index.php
如何使用/ activate文件夹中的index.php文件解析/ 9ajebaidblahdeblahblah2020?
我尝试过...
$current_url = $_SERVER['REQUEST_URI'];
echo $current_url;
//OR
var_dump($_SERVER['REQUEST_URI']);
我想做的是(目的)...
$current_url = explode("/",$_SERVER['REQUEST_URI']);
//echo $current_url[2];
提前感谢您的帮助。
解决方法
使用以下代码在.htaccess
项目文件夹中添加activate
文件:
RewriteEngine On
RewriteRule ^/?activate/(.+)$ /activate/index.php?val=$1 [NC,L,P]
演示:https://htaccess.madewithlove.be?share=aa64900e-ba78-4f17-9369-326f4384dd47
稍后在您的index.php
文件中,您可以将其用作:
<?php
echo $_GET['val'];
,
您的服务器上没有名为9ajebaidblahdeblahblah2020
的页面。
您可以使用htaccess(https://httpd.apache.org/docs/current/howto/htaccess.html)将所有URL重定向到index.php。
在此处查看更多详细信息: Redirect all to index.php using htaccess
,<php
$url = $_SERVER['REQUEST_URI'];
$route_path = parse_url($url,PHP_URL_PATH);
$segments = array_filter(explode("/",$route_path));
print_r($segments);
您将获得以下结果,
Array( [1] =>激活, [2] => 9ajebaidblahdeblahblah2020 )
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。