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条)

报告相同问题?

悬赏问题

  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding