如何重定向只有当确切的URL匹配? [英] How to redirect only when exact url matches?
本文介绍了如何重定向只有当确切的URL匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想重定向与Apache的.htaccess。我有以下的codeS
I'm trying to redirect with apache .htaccess. I have the following codes
redirectMatch 301 /user http://clients.mydomain.com
它的工作原理pretty的好,但我不希望/用户/登录,以定向为http://clients.mydomain.com/login
我如何prevent呢?
How do I prevent it?
推荐答案
简单的添加 ^
来开始和 $
到最后
Simple add a ^
to beginning and a $
to the end
^
告诉告诉正则表达式匹配URL的开头
^
tells tells the regex to match the beginning of the url
$
告诉告诉正则表达式的URL的末尾匹配
$
tells tells the regex to match the end of the url
redirectMatch 301 ^/user$ http://clients.mydomain.com
所以,现在您的规则将只匹配 /用户
,而不是 /一些/用户
或 /用户/名称
或 /一些/用户/名称
注意:如果您想匹配 /用户/
和 /用户
然后使用 ^ /用户/?$
NOTE: If you want to match /user/
and /user
then use ^/user/?$
?
表示,零至一倍匹配previous字符/组
?
says to match the previous character/group zero to one times
这篇关于如何重定向只有当确切的URL匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文