[英]htaccess rewrite specific parameter with dot
I have an issue to rewrite url which is like: 我有一个重写网址的问题,例如:
http://examplepage.com/news/?aid=n_557eb95ed07360.45147988
to 至
http://examplepage.com/some-other-name
but it needs to be only this url if parameter changes it should do nothing. 但是,如果参数更改,则仅需使用此url,否则它什么也不做。 I think the problem is the dot in the parameter?
我认为问题是参数中的点?
My current .htaccess for this matter is like this: 我当前对此问题的.htaccess如下所示:
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
Any help appreciated. 任何帮助表示赞赏。 Thanks.
谢谢。
Escape the dot with \\.
用
\\.
转义点\\.
to match a literal dot, not "any character". 匹配文字点,而不是“任何字符”。
A .
一
.
means " match any character " in a regular expression, so 表示在正则表达式中“ 匹配任何字符 ”,因此
/^aid=n_557eb95ed07360.45147988$/
will match 将匹配
aid=n_557eb95ed07360.45147988
aid=n_557eb95ed07360045147988
aid=n_557eb95ed07360145147988
aid=n_557eb95ed07360245147988
...
but 但
/^aid=n_557eb95ed07360\.45147988$/
will only match 只会匹配
aid=n_557eb95ed07360.45147988
As Drakes said, adding an escape to the dot should do the trick. 正如Drakes所说,在点上添加转义符可以解决问题。
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360\.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
Or, if aid
is going to be dynamic, then you can use: 或者,如果
aid
将是动态的,则可以使用:
RewriteCond %{QUERY_STRING} ^aid=(.*)$
And if you want to search for aid
is any part of the query: 如果要搜索
aid
,则查询的任何部分:
RewriteCond %{QUERY_STRING} !(^|&)aid=(.*)$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.