doukuipai8544 2013-11-30 17:04
浏览 105
已采纳

使用url重写访问$ _GET []数组

I'm building a website for a hair saloon. I got all the time that i need so I i started to build my MVC framework just to better understand MVC. The core of MVC is url rewriting.

RewriteRule ^(.*)/?$ index.php?url=$1 [L]

That would result in this...

www.example.com/register
$_GET['url'] = 'register'

I decided to make the page post/redirect/get pattern. So when I redirect, the url should be something like this...

www.example.com/register/John/Doe/mail

or something similar. That value is entirely in the $_GET['url'] variable. Is there a way to make the url look like this...

www.example.com/register/?name=John&lastName=Doe&mail=johdoe@gmail.com

which would be accessabile with $_GET['name'], $_GET['lastName'] etc...?

I know that there is an entire uri in the $_SERVER['REQUEST_URI'] variable, but i was wondering is there a cleaner way to get the values?

  • 写回答

2条回答 默认 最新

  • doumou1864 2013-11-30 17:14
    关注

    You will need to do your own parsing. I'd strongly recommend you use $_SERVER['QUERY_STRING'] instead, that will also enable you to simply omit the url= part.

    Alternatively you can setup more Rewrite Rules, but that has its downsides, like no dynamic handling without generating those rules on the fly (which is also impossible with Webservers other than Apache, like nginx)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站