查询字符串 &修改改写 [英] Query Strings & Mod ReWrite

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

问题描述

我对 ReWrite 并不太缺乏经验(虽然也不是大师),所以我希望有人能帮助我.

I'm not too inexperienced with ReWrite (not a master either, though) so I was hoping somone might be able to help me.

RewriteRule ^$ index.php?page=home [NC]
RewriteRule ^adm$ index.php?page=adm_home [NC]
RewriteRule ^adm/stats index.php?page=adm_stats [NC]

以上是我的 .htaccess 文件的片段.如您所见,当有人访问 http://www.example.com/adirectory/ 时实际上调用 index.php?page=home,类似地,如果有人访问 http://www.example.com/adirectory/adm/ 它仍然会在adirectory"中调用 index.php?page=adm_home.

Above is a snippet of my .htaccess file. As you can see, when someone visits http://www.example.com/adirectory/ it actually calls on index.php?page=home, similarly if someone goes to http://www.example.com/adirectory/adm/ it will still call index.php?page=adm_home within the "adirectory".

我想要实现的是:我希望能够在我的页面上显示警报,为此我只想能够添加 alert=n(其中 n 是一个数字),从而有重定向为 index.php?page=home&alert=n

What I'm wanting to achieve is this: I want to be able to display alerts on my pages, and to do this I want to simply be able to add alert=n (where n is a number) and thus have the redirect as index.php?page=home&alert=n

但是,我不明白这是怎么做到的,正则表达式让我很困惑.寻求您的帮助.

However, I can't understand how this can be done, regex is confusing me. Seeking your help.

推荐答案

您可以设置 QSA 标志 自动将最初请求的查询字符串附加到新的查询字符串中:

You can set the QSA flag to automatically append the originally requested query string to the new one:

RewriteRule ^$ index.php?page=home [L,QSA]
RewriteRule ^adm$ index.php?page=adm_home [L,QSA]
RewriteRule ^adm/stats$ index.php?page=adm_stats [L,QSA]

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

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