htaccess和MVC路由 [英] htaccess and MVC routing

查看:100
本文介绍了htaccess和MVC路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我开始编写一个微型MVC基础代码,我可以在客户端网站上使用它,它也使用与CakePHP相同类型的路由器类.我目前的网址显示如下:

Well i started coding a mini MVC base that I can just use on client websites, which also uses the same type of router class as CakePHP. I currently have the url display like this:

http://localhost/mvc/index.php?page=blog/viewall

哪个获取控制器并告诉其功能,就像CakePHP index(),view()等等.

Which gets the controller and tells it the function, just like CakePHP index(), view(), and so on.

现在,我不确定如何使用.htaccess使网址看起来像这样

Now, I'm not sure how I can make the url look like this with .htaccess

http://localhost/mvc/blog/viewall

我试图将其添加到.htaccess文件中:

I was trying to add this in the .htaccess file:

RewriteRule ^(.*)$ index.php?page=$1 [QSA]

推荐答案

具有这样的重定向规则:

Have your redirect rule like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/mvc/index.php/.*
RewriteRule ^/mvc/(.*) /mvc/index.php?page=$1 [QSA,L]

这篇关于htaccess和MVC路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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