Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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/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
Apache RedirectMatch 301-仅目录排除文件、子目录、查询字符串_Apache_.htaccess_Mod Rewrite_Url Redirection - Fatal编程技术网

Apache RedirectMatch 301-仅目录排除文件、子目录、查询字符串

Apache RedirectMatch 301-仅目录排除文件、子目录、查询字符串,apache,.htaccess,mod-rewrite,url-redirection,Apache,.htaccess,Mod Rewrite,Url Redirection,我环顾四周,但一切似乎都与我想要的相反。我要做的就是重定向目录,排除目录URL之后的所有内容。所以我有一个有效的方法 RedirectMatch 301 /blog/ http://www.mynewblog.com/ 但我需要它排除(而不是重定向)附加在目录或文件和子目录之后的查询字符串。所以我仍然想访问这些URL http://www.myoldblog.com/blog/?wpdmact=process http://www.myoldblog.com/blog/page/2 http:

我环顾四周,但一切似乎都与我想要的相反。我要做的就是重定向目录,排除目录URL之后的所有内容。所以我有一个有效的方法

RedirectMatch 301 /blog/ http://www.mynewblog.com/
但我需要它排除(而不是重定向)附加在目录或文件和子目录之后的查询字符串。所以我仍然想访问这些URL

http://www.myoldblog.com/blog/?wpdmact=process
http://www.myoldblog.com/blog/page/2
http://www.myoldblog.com/blog/page.php
但是
/blog/
之后的一切仍然被重定向。那么有没有办法在htaccess文件中排除这个问题呢。如果有人已经发布了答案,我找不到,请表示感谢和抱歉。

尝试:

RewriteEngine On

RewriteCond %{QUERY_STRING} !^wpdmact=process
RewriteCond $1 !^page/2
RewriteCond $1 !^page.php
RewriteRule ^blog/(.*)$ http://www.mynewblog.com/ [L,R=301]
如果要与查询字符串匹配,则需要使用mod_rewrite而不是mod_alias,但这将重定向以
/blog/
*开头的所有内容,但如果查询字符串为
wpdmact=process
或以下路径为
page/2
page.php
则除外8请尝试以下操作:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^blog/?$ http://www.mynewblog.com/ [R,L]
请注意,要使上述规则起作用,您需要启用
mod_rewrite
。虽然
RedirectMatch
指令随
mod_alias
模块提供,但重写是通过单独的模块完成的