.htaccess中经常EX pression匹配任何字符 [英] Htaccess Regular expression to match any character

查看:148
本文介绍了.htaccess中经常EX pression匹配任何字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的htaccess的这个常规EX pression:

 的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^([A-ZA-Z0-9 _- \ S] +)/([A-ZA-Z0-9 _- \ S] +)/ $的index.php参数1 = $ 1安培;?参数2 = $ 2 [L ,NC]
 

问题是这样的作品与此的任何变化:

  example.com/search/test产品123
example.com/search/test+product+123
example.com/search/testproduct123
example.com/search/test%20product%20123
 

但是,当我抛出一个句号(。)到它不匹配,我得到一个404的消息。我是一个菜鸟到正规EX pression并不能找出语法添加到[A-ZA-Z0-9 _- \ S]允许所有字符。我相信[*]会工作,但它仍然给我一个404.I要允许在期间与我目前有重写规则。

更新:

所以,我怎么会拿这样的:

  ^([A-ZA-Z0-9 _- \ S] +)/([A-ZA-Z0-9 _- \ S] +)/ $?
 

和允许它识别这样的字符串:

 搜索/短吨。+查尔斯
 

解决方案

要允许一个点(。),你要逃避它,所以使用 \ 而不是。您也可以使用 [^ ABC] 来让所有字符,但农行的。

修改

要允许在路径点,用这个:

^([A-ZA-Z0-9 _- \ S \。] +)/([A-ZA-Z0-9 _- \ S \。] +)/?$

I am using this regular expression on my htaccess:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_-\s]+)/([A-Za-z0-9_-\s]+)/?$ index.php?param1=$1&param2=$2 [L,NC]

The problem is this works with any variation of this:

example.com/search/test product 123
example.com/search/test+product+123
example.com/search/testproduct123
example.com/search/test%20product%20123

But when I throw a period (.) into it it doesn't match and I get a 404 message. I'm a rookie to regular expression and cannot figure out the syntax to add to [A-Za-z0-9_-\s] to allow all characters. I believe [.*] would work but it still send me to a 404.I want to allow period in the rewrite rule with what I currently have.

Updated:

So how would I take this:

^([A-Za-z0-9_-\s]+)/([A-Za-z0-9_-\s]+)/?$

And allow it to recognize a string like this:

search/st.+charles

解决方案

To allow a dot (.) you have to escape it, so use \. instead of .. You can also use [^abc] to allow all characters but abc.

Edit:

To allow dots in the path, use this:

^([A-Za-z0-9_-\s\.]+)/([A-Za-z0-9_-\s\.]+)/?$

这篇关于.htaccess中经常EX pression匹配任何字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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