Php htaccess用点重写特定参数
我有一个问题需要重写url,如下所示:Php htaccess用点重写特定参数,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有一个问题需要重写url,如下所示: http://examplepage.com/news/?aid=n_557eb95ed07360.45147988 到 但它只需要是这个url,如果参数发生变化,它应该什么也不做。我认为问题在于参数中的点 我目前对此事的.htaccess如下: RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360.45147988$ RewriteRule ^news/$ /some-other-url [NC,L] 谢
http://examplepage.com/news/?aid=n_557eb95ed07360.45147988
到
但它只需要是这个url,如果参数发生变化,它应该什么也不做。我认为问题在于参数中的点
我目前对此事的.htaccess如下:
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
谢谢你的帮助。谢谢。用
\.
转义点以匹配文字点,而不是“任何字符”
在正则表达式中表示“”,因此
/^aid=n_557eb95ed07360.45147988$/
将匹配
aid=n_557eb95ed07360.45147988
aid=n_557eb95ed07360045147988
aid=n_557eb95ed07360145147988
aid=n_557eb95ed07360245147988
...
但是
只会匹配
aid=n_557eb95ed07360.45147988
演示:正如德雷克斯所说,在圆点上添加一个转义符应该可以达到目的
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360\.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
或者,如果aid
将是动态的,那么您可以使用:
RewriteCond %{QUERY_STRING} ^aid=(.*)$
如果要搜索aid
是查询的任何部分:
RewriteCond %{QUERY_STRING} !(^|&)aid=(.*)$
可能是重复的,非常感谢。Drakes的解决方案是这样的,但有了它,我可以过滤那些参数值。没问题。您刚才在问题中写道“如果参数发生更改,它只需要是这个url,它不应该做任何事情”
RewriteCond %{QUERY_STRING} ^aid=(.*)$
RewriteCond %{QUERY_STRING} !(^|&)aid=(.*)$