mod-rewrite和查询字符串 [英] mod rewrite and query strings
本文介绍了mod-rewrite和查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图重写一些查询字符串我有我的网址是这样的:
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
但不能看着办吧......
But can't figure it out...
它应该也工作,如果我只有例如页的参数,因为我并不总是有这些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 code。
The easiest way is to do most of the parsing in PHP code.
使用的RewriteRules像
Use rewriterules like
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
,然后访问请求的URI( $ _ SERVER ['REQUEST_URI']
)从PHP,正如你希望它解析为尽可能多的部分。
And then access the request uri ($_SERVER['REQUEST_URI']
) from PHP, and parse it into as many parts as you want.
这篇关于mod-rewrite和查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文