阿帕奇/mod-rewrite:路线一切的index.php? [英] Apache/Mod Rewrite: Route everything to index.php?

查看:219
本文介绍了阿帕奇/mod-rewrite:路线一切的index.php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个前端控制器将处理页面请求,通过解析

I'm writing a front-controller that will handle page requests, by parsing

$_SERVER['REQUEST_URI'].

我想获得路由到的index.php所有请求

I would like to get all requests routed to /index.php

一些例子如下:

example.com/page2?foo=bar
example.com/page2/?foo=bar
example.com/page/action/123/
example.com/page/action/123

什么是正则表达式规则,我必须在.htaccess中写?

What is the regexp rule that i have to write in .htaccess ?

和我需要一个额外的规则,使example.com/images/目录将工作作为'正常'的目录?

And do I need an extra rule so that example.com/images/ directory would work as 'normal' directory?

推荐答案

您可以尝试这样的:

RewriteCond %{REQUEST_URI} !^/dir_under_rootdocument/index\.php
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|js|css)$
RewriteRule (.*) dir_under_rootdocument/index.php/$1 [L,QSA]

这篇关于阿帕奇/mod-rewrite:路线一切的index.php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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