URL rewriting in PHP when several values are being passed in the URL

后端 未结 1 1596
野趣味
野趣味 2020-12-12 05:37

I am currently researching how to modify URLs in php using Mod rewrite.

A typical URL could look like this:

http://www.fitness.com/find_a_pt/?county=&con

相关标签:
1条回答
  • 2020-12-12 06:08

    I always use the same mode_rewrite rules:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    

    With this rules everything is forwared to index.php. So you are free to implement every url logic with PHP.

    You can get the request uri with $_SERVER['REQUEST_URI'] and do whatever you want.

    It is nice to have a Routing class with regex rules to parse the uri. Look at an example here and also read how the big frameworks like Zend, Code Igniter etc. do it. (The rewrite rule I provided is from Zend Framework by the way)

    0 讨论(0)
提交回复
热议问题