Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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/5/url/2.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重定向同一域但不同目录上具有查询字符串的URL_.htaccess_Url_Redirect - Fatal编程技术网

.htaccess 使用htaccess重定向同一域但不同目录上具有查询字符串的URL

.htaccess 使用htaccess重定向同一域但不同目录上具有查询字符串的URL,.htaccess,url,redirect,.htaccess,Url,Redirect,我试图将一个页面连同查询字符串重定向到另一个页面。 例如: 下面的URL http://example.com/firstdir/?abc=xyz 需要重定向到同一域上具有相同查询字符串的以下URL http://example.com/seconddir/?abc=xyz 当URL中没有添加查询字符串时,它应该保持在同一页面上,并且不会重定向 我已经试着解释我在寻找什么,请帮助 谢谢。只需将.htaccess放入根文件夹,它将处理递归文件夹。您可以在文档\u root/.htaccess文

我试图将一个页面连同查询字符串重定向到另一个页面。 例如:

下面的URL

http://example.com/firstdir/?abc=xyz
需要重定向到同一域上具有相同查询字符串的以下URL

http://example.com/seconddir/?abc=xyz
当URL中没有添加查询字符串时,它应该保持在同一页面上,并且不会重定向

我已经试着解释我在寻找什么,请帮助


谢谢。

只需将.htaccess放入根文件夹,它将处理递归文件夹。

您可以在
文档\u root/.htaccess文件中使用此代码:

RewriteEngine On

RewriteCond %{QUERY_STRING} .+
RewriteRule ^firstdir/?$ /seconddir [NC,L,R=302]

查询字符串将自动转到目标URL

感谢您的回复,.htaccess文件已位于根文件夹中。感谢anubhava,我已尝试了给定的代码,但未能成功。可能是因为我使用WordPress,它与WP默认重写规则冲突。我使用了插件安全重定向管理器,它解决了这个问题。感谢您的帮助…如果是Wordpress,请将规则作为第一条规则放在上面,就在WP.htaccess中
rewiteEngine
行的下面