Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
.htaccess htaccess重定向精确匹配,排除所有查询字符串_.htaccess - Fatal编程技术网

.htaccess htaccess重定向精确匹配,排除所有查询字符串

.htaccess htaccess重定向精确匹配,排除所有查询字符串,.htaccess,.htaccess,我正在尝试重定向http://domain.com/search至http://domain.com 但是,我也有类似于http://domain.com/search?q=someword 目前我有: redirectMatch 301 http://domain.com/search$ http://domain.com 即使它正确地重定向http://domain.com/searchurl,它还重定向任何http://domain.com/search?q=somewordurl到ht

我正在尝试重定向
http://domain.com/search
http://domain.com

但是,我也有类似于
http://domain.com/search?q=someword

目前我有:

redirectMatch 301 http://domain.com/search$ http://domain.com
即使它正确地重定向
http://domain.com/search
url,它还重定向任何
http://domain.com/search?q=someword
url到
http://domain.com/?q=someword
,这是我不想要的


我做错了什么?

我建议您在htaccess中使用
mod_rewrite
而不是
mod_alias

RewriteEngine On
RewriteBase /
RewriteRule ^search/?$ / [L,R=301]

在目标末尾添加一个

RedirectMatch 301 ^/search$ http://domain.com/?
但是,这将导致浏览器位置栏中URL的末尾出现一个
。如果改用mod_rewrite,则不会看到

RewriteEngine On
RewriteRule ^/?search$ /? [L,R=301]

RewriteBase/上的RewriteEngine已存在于我的htaccess文件中,因此我刚刚添加了第3行,但它仍然不起作用。如果您使用此(我的)代码,则必须删除您的
RedirectMatch
子句。这将完全删除字符串。我只想保留url的完整性,如果它的结尾有?q=someword,而不是完全删除它。我想这是我的错,我现在明白了,首先我没有正确解释我的情况