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
Apache 删除URL中查询字符串中的部分字符串_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 删除URL中查询字符串中的部分字符串

Apache 删除URL中查询字符串中的部分字符串,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有一个如下所示的输入URL: http://localhost/20north/Numark/product/1/B$@!00$@!4JPPO94$@! 在将其重定向到新URL时,我需要查找并删除URL最后部分中出现的所有“$@!”,使其成为: http://localhost/20north/Numark/product/1/B004JPPO94 注意:最后一部分可以是任何内容,而不仅仅是B$@!00$@!4JPPO94$@。还有,$@的位置可以位于最后一部分的任何位置。如果使用php,

我有一个如下所示的输入URL:

http://localhost/20north/Numark/product/1/B$@!00$@!4JPPO94$@!
在将其重定向到新URL时,我需要查找并删除URL最后部分中出现的所有“$@!”,使其成为:

http://localhost/20north/Numark/product/1/B004JPPO94

注意:最后一部分可以是任何内容,而不仅仅是
B$@!00$@!4JPPO94$@。还有,
$@的位置可以位于最后一部分的任何位置。

如果使用php,可以执行以下操作:

<?php 
    $this_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if( strpos($this_url, '$@!') !== false ) 
       die(header('Location: ' . str_replace('$@!', '', $this_url))); 
?>


编辑:将代码更新为动态

如果您使用的是php,则可以执行以下操作:

<?php 
    $this_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if( strpos($this_url, '$@!') !== false ) 
       die(header('Location: ' . str_replace('$@!', '', $this_url))); 
?>


编辑:使用mod_rewrite将代码更新为动态

,您只需要以下规则:

RewriteRule ^(.*)\$@!(.*)$ $1$2 [N]
编辑:

事实上,
$@出现问题位于URI的末尾。添加额外规则以删除尾随匹配项似乎可以解决此问题:

RewriteRule ^(.*)\$@!$ $1
RewriteRule ^(.*)\$@!(.*)$ $1$2 [N]

不太清楚为什么会发生这种情况。

使用mod_rewrite,您只需要以下规则:

RewriteRule ^(.*)\$@!(.*)$ $1$2 [N]
编辑:

事实上,
$@出现问题位于URI的末尾。添加额外规则以删除尾随匹配项似乎可以解决此问题:

RewriteRule ^(.*)\$@!$ $1
RewriteRule ^(.*)\$@!(.*)$ $1$2 [N]

不太清楚为什么会发生这种情况。

谢谢,但我们没有使用php…apache模块…我现在还将此添加到问题中。谢谢你,谢谢你,但是我们没有使用php…apache模块…我现在也把这个添加到问题中。谢谢你