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

   IT问题网   2019-08-16 00:00:00

问 题

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

我有这样的url: http://knjiskicrv.comoj。 com / index.php页面=书和放大器;?id = 1

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

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

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

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

希望有人帮助。谢谢你。

解决方案

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

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

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

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

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

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

rewriteengine叙述上
的rewritecond%{request_uri}!^资产/
重写规则。*的index.php
 

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

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

标签:重写隐藏暗藏作出查询不错



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

htaccess的URL路由的PHP MVC?(htaccess URL routing for PHP MVC)

problem i've been searching and have yet to find an artic ...

的.htaccess规则相应的HTTP链接,HTTP和HTTPS重定向到HTTPS?(.Htaccess rules to redirect respective HTTP links to HTTP and HTTPS to HTTPS)

problem first, here's the .htaccess rule i cu ...

使用的.htaccess追加html的URL路径的背后(using .htaccess to append .html behind url path)

problem people are coming into my website like this: sit ...

的.htaccess迫使对SSL错误页面(.htaccess forcing error pages on SSL)

problem i have the following piece of code in ...

可变301重定向URL(301 redirect URL with variable)

problem i want to use htaccess to 301 redirect (not rewri ...

htaccess的重定向example.com/index.php到example.com/home~~V(htaccess redirect example.com/index.php to example.com/home)

problem thanks in advance, i am trying to redirect anyone ...

htaccess的重写规则问题(.htaccess Rewrite Rule Problems)

problem can anyone help me with htaccess rewr ...

htaccess的子域名与所有的变量文件参数(.htaccess sub domain as file parameter with all the variables)

problem i want to make this url redirect usin ...

字preSS定制的mod_rewrite - totalnoob?(Wordpress custom mod_rewrite - totalnoob)

problem i'm trying to make a custom mod_rewrite rule for ...

我怎样才能让我的网址,从这个例子中友好吗?(How can I make my urls friendly from this example)

problem my site currently displays like this (when clicki ...

htaccess的问题强制SSL(.htaccess issue to force SSL)

problem i activated ssl on one of my sites (based on word ...

IfModule不会出现是工作?(IfModule doesn't appear to be working)

problem if i use this: lt;ifmodule mod_rewrite.cgt; rewr ...

我怎样才能利用外界信息的URL重写?(How can I get use outside information in url rewrites)

problem hopefully some of you .htaccess gurus can help me ...

基于URL到一个新的页面的RewriteCond重写规则进行的.htaccess,定期EX pression(RewriteCond RewriteRule for .htaccess based on URL to a new page, regular expression)

problem i have an interesting rewriterule and i am not su ...

的.htaccess,mod_rewrite的,正则表达式用目录和文件类型(.htaccess, mod_rewrite, regex with directory and filetype)

problem i want to do a rewrite with the following conditi ...

.htaccess的语言重定向310错误(Htaccess language Redirect 310 error)

problem i have a two language site swedish sidewww.site ...

重定向一切的index.php(Redirection everything to index.php)

problem i wan't to redirect everything to index.php exepe ...

生成SE友好的URL的.htaccess国防部重写(Generating SE friendly URL .htaccess mod rewrite)

problem i've a url which get file name through get method ...

htaccess的子域名重定向(htaccess subdomain redirect)

problem i've searched around and tried a few ...

UrlRewrite 3 GET请求(UrlRewrite with 3 get request)

problem i'm working on a project and stuck on urlrewrite. ...