Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess用点重写特定参数_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php htaccess用点重写特定参数

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] 谢

我有一个问题需要重写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]

谢谢你的帮助。谢谢。

\.
转义点以匹配文字点,而不是“任何字符”

在正则表达式中表示“”,因此

/^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=(.*)$