.htaccess不会在RewriteRule上转义问号 [英] .htaccess doesn't escape question mark on RewriteRule

查看:57
本文介绍了.htaccess不会在RewriteRule上转义问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧类型的单一登录"网站.父网站使用以下网址将用户发送到我的网站:

I have a website with an old type of Single Sign On. A parent website sends users to my website with a URL like:

http://blabla.test/index.php?gid = abcd1234& u = bcanata& id = 11472

http://blabla.test/index.php?gid=abcd1234&u=bcanata&id=11472

并且我想这样重写它:

http://blabla.test/login/abcd1234/bcanata/11472

http://blabla.test/login/abcd1234/bcanata/11472

我创建了一个 .htaccess 文件,如下所示:

I have created a .htaccess file as following:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index.php?gid=(.*)&u=(.*)&id=(.*)$ login/$1/$2/$3 [L]

我尝试这样在URL中转义问号:

I tried escaping the question mark in the URL as this:

RewriteRule ^index.php\?gid=(.*)&u=(.*)&id=(.*)$ login/$1/$2/$3 [L]

但是,不幸的是,这两个规则都不匹配并重写URL,我不明白为什么.

But, unfortunately both these rules don't match and rewrite the URL, which I can't understand why.

推荐答案

您不能以RewriteRule伪指令的形式与url QueryString进行匹配.您只能在RewriteRule中与URL路径进行匹配(即: index.php ).?符号后的网址部分是URL QueryString.您将需要与 RewriteCond 中的%{QUERY_STRING} 变量进行匹配.

You can not match against url QueryString in pattern of a RewriteRule directive. You can only match against url path ( ie : index.php ) in RewriteRule. Url part after the ? sign is URL QueryString. you will need to match against %{QUERY_STRING} variable in RewriteCond .

RewriteEngine on

RewriteCond %{QUERY_STRING} ^gid=([^&]+)&u=([^&]+)&id=([^&]+)$ [NC]
RewriteRule ^index.php$  /login/%1/%2/%3? [L,R]

这篇关于.htaccess不会在RewriteRule上转义问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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