PHP MVC有更好的htaccess [英] PHP MVC with better htaccess

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

问题描述

我不知道该怎么htaccess的作品,而它的理论只是不会在我的头上连接不管我有多少教程阅读。

我建立了一个简单的MVC框架,工作很漂亮,但我不喜欢我处理htaccess的方式。要重写URL的正确,这是我在做什么:

  RewriteEngine叙述上
?重写规则^用户/([^ /] +)(/([^ /] +))$控制器/ users.php方法= $ 1安培;参数= $ 3
 

如果我添加一个新的控制器,然后我必须进入htaccess的,并添加一个新行:

?<?pre> 重写规则^接入/([^ /] +)(/([^ /] +))$控制器/ access.php方法= $ 1安培;参数= $ 3

有没有一种方法,使所有的自动带通配符的领域,所以我没有访问htaccess的我每次做一个更新?

解决方案

您可以试试这个:

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
?重写规则^([^ /] +)/([^ /] +)(/([^ /] +))$控制器/ $ 1.PHP方法= $ 2及?参数= $ 4个
 

这两个额外的规则将跳过重写,如果确实引用的文件或directoy存在于磁盘,例如在:它不会试图改写为 http://site.com/images/请求logo.jpg

I have no idea how htaccess works, and the theory of it just wont connect in my head no matter how many tutorials I read.

I am building a simple MVC framework which works beautifully, except I don't like the way I am dealing with htaccess. To rewrite the URL's properly, this is what I am doing:

RewriteEngine on
RewriteRule ^users/([^/]+)(/([^/]+))?$ controller/users.php?method=$1&param=$3

If I add a new controller, I then have to go into htaccess and add a new line:

RewriteRule ^access/([^/]+)(/([^/]+))?$ controller/access.php?method=$1&param=$3

Is there a way to make it all automatic with wildcard fields so I don't have to access htaccess every time I do an update?

解决方案

You can try this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)(/([^/]+))?$ controller/$1.php?method=$2&param=$4

The two extra rules will skip the rewrite if the file or directoy referenced actually exists on the disk, eg: it won't try to rewrite requests for http://site.com/images/logo.jpg.

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

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