为什么在我重写条件正则表达式似乎没有赶上? [英] why does the regex in my rewrite condition seem to not catch?

查看:108
本文介绍了为什么在我重写条件正则表达式似乎没有赶上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似以下网址:

mysite.com/eng?sentence=dog

和我想重写它们作为

mysite.com/eng/dog

所以我想替换?一句话= 用/

我已经尝试了所有的以下内容:

I have tried all of the following:

RewriteCond %{THE_REQUEST} ^GET\ sentence= [NC]
RewriteRule ^ /%1 [NC,L,NE]

RewriteCond %{THE_REQUEST} ^GET\ \?sentence= [NC]
RewriteRule ^ /%1 [NC,L,NE]

RewriteCond %{THE_REQUEST} ^GET\ \?sentence=([^/?&\s]+) [NC]
RewriteRule ^ /%1 [NC,L,NE]

RewriteCond %{THE_REQUEST} ^GET\s/+\?sentence=([^/?&\s]+) [NC]
RewriteRule ^ /%1 [NC,L,NE]

然后我试图访问的网址:

then I tried accessing the URL:

mysite.com/eng?sentence=cat

但它保持原样。我认为我的正则表达式的逻辑是不正确的,并重写cond是永远不会满足。我总是有麻烦的正则表达式。

but it stays as it is. I assume my regex logic is not correct and the rewrite cond is never satisfied. I always have trouble with regex.

推荐答案

您可以使用此规则:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(eng)\?sentence=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/? [L,R]

这将重定向 http://mysite.com/eng?sentence=dog http://mysite.com/eng/dog /

这篇关于为什么在我重写条件正则表达式似乎没有赶上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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