问题描述
我有一个为用户创建商店的应用程序,他们可以使用我的仪表板创建单个页面商店。创建商店后生成的最终URL如下
I have an application which creates stores for users and they can create a single page store using my dashboard.The final URL generated after they create the store is as follows
baseurl/store/{username}/{random number}
现在如何访问{用户名}和{随机数}。
Now how can I access the {username} and {random number}.
如果目录 store中有索引文件
--store
---- index.php我可以从url中获取上面的用户名和随机数吗?如果这是在codeingiter中进行的话,事情就很容易了,我可以用名称存储创建一个控制器并获取uri。段。但是如何在纯PHP中完成同样的操作而没有任何框架工作。请提供帮助
If I have a index file in directory 'store'--store----index.php will I be able to fetch the above username and random number from the url?If this was in codeingiter things would have been easy , and I could make a controller with name store and get the uri segments.But how can I do the same in pure PHP without any frame work.Please do help
推荐答案
您必须使用 .htaccess
为此。
因此,请在项目目录的根目录(其中 index.php
是)。
So create this file at the root of your project directory (where index.php
is).
.htaccess 内容:
RewriteEngine On
RewriteRule ^store/([a-zA-Z0-9\_]+)/([0-9]+)$ index.php?username=$1&rand=$2
index.php 内容:
<?php
var_dump($_GET);
?>
现在尝试使用以下网址: mywebsite.com/store/jack_97/ 354
,您应该得到 $ _ GET
的转储,告诉您此数组包含两个键: username和 rand
Now try using an url like : mywebsite.com/store/jack_97/354
and you should end up with a dump of $_GET
telling you that this array contains two keys : "username" and "rand"
这篇关于仅在纯PHP中使用斜线的URL,例如codeigniter uri模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!