简体   繁体   English

PHP中的URL模式匹配

[英]URL pattern matching in PHP

I'm trying to implement java like url pattern matching in php. 我正在尝试在php中实现java,例如url模式匹配。 Suppose i have a link which leads to a file called find.php (Example is shown below) 假设我有一个链接,该链接指向名为find.php的文件(示例如下所示)

http://www.xyz.com/MyWebsite/TryToFind/find.php?search=abc+def http://www.xyz.com/MyWebsite/TryToFind/find.php?search=abc+def

Then i want to expose the follwing link to the users, say, 然后,我想向用户公开以下链接,例如,

http://www.xyz.com/Search?search=abc+def http://www.xyz.com/Search?search=abc+def

then i want to match this(2nd url pattern) url to the one i have provided above(1st url pattern) using a controller. 那么我想使用控制器将这个(第二个网址格式)url匹配到我上面提供的一个(第一个网址格式)URL。 This is because i want to hide the exact uri pattern to the user and also the hide the extension which i have used. 这是因为我想向用户隐藏确切的uri模式,同时也隐藏我已使用的扩展名。

Please Help Me Guys... 请帮我...

Regards, Abilash 问候,Abilash

If you are using apache (which I assume you are as you have tagged .htaccess ) as your http server then you can use Apache's Mod_Rewrite Module. 如果您使用apache(假设您已将.htaccess标记为apache)作为http服务器,则可以使用Apache的Mod_Rewrite模块。 It usually ships with most installations of Apache these days and anyways you can install one yourself if it is not present. 如今,Apache的大多数安装通常都附带了它,并且如果不存在,您可以自己安装一个。

Mod_Rewrite will enable you to achieve what you desire, In fact it is designed for that purpose only. Mod_Rewrite将使您能够实现所需的目标,实际上,它仅用于该目的。 While php frameworks like CodeIgniter provide some programming support for Mod_Rewrite, working directly with .htaccess using the Regex will render you with more power and flexibility. 虽然像CodeIgniter这样的php框架为Mod_Rewrite提供了一些编程支持,但是使用Regex直接与.htaccess使用将为您提供更多的功能和灵活性。

A full explaination is difficult here. 这里很难进行完整的解释。 But this was the tutorial I found handy when learning the same. 但这我学习相同的教程时很方便的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM