简体   繁体   中英

URL pattern matching in PHP

I'm trying to implement java like url pattern matching in php. Suppose i have a link which leads to a file called find.php (Example is shown below)

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

then i want to match this(2nd url pattern) url to the one i have provided above(1st url pattern) using a controller. This is because i want to hide the exact uri pattern to the user and also the hide the extension which i have used.

Please Help Me Guys...

Regards, 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. It usually ships with most installations of Apache these days and anyways you can install one yourself if it is not present.

Mod_Rewrite will enable you to achieve what you desire, In fact it is designed for that purpose only. 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.

A full explaination is difficult here. But this was the tutorial I found handy when learning the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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