mod重写和查询字符串 [英] mod rewrite and query strings

查看:29
本文介绍了mod重写和查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重写我的 URL 中的一些查询字符串,如下所示:

I'm trying to rewrite some query strings I have in my URL like this :

foo.com/index.php?page=admin&view=news&action=edit&id=3

foo.com/admin/news/edit/3

但是想不通...

例如,如果我只有页面"参数,它也应该可以工作,因为我的网址中并不总是有这 4 个参数(页面、视图、操作、id).

it should also works if I only have the 'page' parameters for example, since I don't always have these 4 parameters (page,view,action,id) in my urls, of course.

有什么建议吗?

推荐答案

最简单的方法是在 PHP 代码中进行大部分解析.

The easiest way is to do most of the parsing in PHP code.

使用像这样的重写器

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule . index.php [L]

然后从 PHP 访问请求 uri ($_SERVER['REQUEST_URI']),并根据需要将其解析为多个部分.

And then access the request uri ($_SERVER['REQUEST_URI']) from PHP, and parse it into as many parts as you want.

这篇关于mod重写和查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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