重写URL隐藏的index.php并作出查询不错 [英] Rewriting url to hide index.php and to make query nice

查看:285
本文介绍了重写URL隐藏的index.php并作出查询不错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发的项目自定义的MVC架构。我是新来的Apache的世界,所以我会AP preciate帮助,这件事情。在Web我发现很多教程,但没有一个像我这样的利益。

I had developed project with custom MVC architecture. And I am new to Apache world, so I would appreciate help with this matter. On a Web I had found lots of tutorials, but no one like mine interests.

我有这样的URL: HTTP://knjiskicrv.comoj。 COM / index.php页面=书和放大器;?ID = 1

我想应该显示是这样的: http://knjiskicrv.comoj.com/book / ID / 1

I would like to be display like this: http://knjiskicrv.comoj.com/book/id/1

或者这样: http://knjiskicrv.comoj.com/index.php?page =常见问题解答 进入这个: http://knjiskicrv.comoj.com/faq

Or this: http://knjiskicrv.comoj.com/index.php?page=faq Into this: http://knjiskicrv.comoj.com/faq

如果在查询中没有(http://knjiskicrv.comoj.com/index.php),我想显示:的 http://knjiskicrv.comoj.com/

If there is no page in query (http://knjiskicrv.comoj.com/index.php), I would like to show: http://knjiskicrv.comoj.com/

也没有查询(http://knjiskicrv.comoj.com/index.php?category=2),它应该是这样的 http://knjiskicrv.comoj.com/category/2

Also with no page in query (http://knjiskicrv.comoj.com/index.php?category=2), it should be like this http://knjiskicrv.comoj.com/category/2

希望有人帮助。谢谢你。

Hope someone will help. Thanks.

推荐答案

其实,你的问题是一个两步proble。你首先需要了解什么是路由的MVC。如果你有自己喜欢的实施框架中的MVC的,你不支持路由,那么这可能意味着你甚至不知道它是怎么工作过。 (悲哀而真实)

Actually, your problem is a two step proble. You first need to understand what is "Routing" in MVC. If you have your own implementation of an MVC like framework and you don't support routing, then it probably means you didn't even know how it worked before. (Sad but true)

在一个MVC框架使用路由器,你设置的路由和路由器分析网址你说我发现这个网址符合您的要求,继续做工作吧。

In an MVC framework you setup routes using a ROUTER and the router analyses the urls for you saying HEY, i found this url that matches your request, go ahead and do work with it.

那么,你的控制器接收到一个请求路由到自身和分析URL,因为他认为合适的。如使用爆炸('/',$ _ SERVER ['REQUEST_URI']),然后读取URL的不同部分映射到预期的变量。

So then, your controller receives a request to route into itself and PARSES the url as he sees fit. Such as using explode('/', $_SERVER['REQUEST_URI']) and then reading the different parts of the url to map to expected variables.

所有这些都是非常理论,因为有在一个自定义的方式来实现它的方式不计其数。你将不得不使用的唯一的事情是有点mod_rewrite的魔法将所有请求传递到您的index.php将路由的一切。看看下面的链接了解mod_rewrite的,它是一个非常复杂的问题:

All of this is very theoretical because there are ZILLIONS of way to implement it in a custom way. The only thing you will have to use is a little mod_rewrite magic to pass all requests to your index.php that will route everything. Look at the url below to learn about mod_rewrite, it's a VERY COMPLEX subject:

http://www.addedbytes.com/for-beginners / URL重写换初学者/

我经常去的是什么,但我没有从家里访问它是这样的:

What i usually go for but i don't have access to it from home is something like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^assets/
RewriteRule .* index.php

这将重定向所有流量的index.php,然后你可以用$ _ SERVER ['REQUEST_URI']分析的要求。资产/文件夹一切都不会被感动和正常工作。

This will redirect all traffic to index.php and you can then use $_SERVER['REQUEST_URI'] to analyze the request. Everything in assets/ folder will not be touched and work correctly.

请注意,我建造了部分脱我的帽子,它可能无法正常工作......

Note, i built that part off my hat, it might not work...

这篇关于重写URL隐藏的index.php并作出查询不错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆