.htaccess何时包含URL?或=



任何人都可以告诉我如何重定向,如果传入的URL包含某些文本,则遇到了真正的麻烦。

例如:

redirectMatch 301/files/9453041/batch-bida http://secondsite.com(这有效)

redirectMatch 301/?load =/files/9453041/batch-bida http://secondsite.com(这不起作用)

仅上述两个重定向中的第一个起作用,不确定为什么,但是第二个包含/?load =不确定。有人可以告诉我第二行需要什么才能工作吗?

或者我想如果可以重定向每个带有" mysite.com/?load=/whateyther/whate/whate/whate"到" mysite.com/whatheatery/what aftery/what aftery"的输入URL,是否可以重新定向每个传入的URL,是否可以使其工作。?

非常感谢您的任何帮助...

以匹配查询字符串(?之后的所有内容),您需要使用重写条件与%{QUERY_STRING}变量匹配:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^load=/files/9453041/batch-BiDA
RewriteRule ^/?$ http://secondsite.com/ [L,R=301]

您也可以使用[OR]

RewriteEngine On
RewriteCond %{QUERY_STRING} ^load=/files/9453041/batch-BiDA [OR]
RewriteCond %{QUERY_STRING} ^load=/files/35356441/batch-546A 
RewriteRule ^/?$ http://secondsite.com/ [L,R=301]

等。

但是,如果您不在乎/files/部分的内容,只需匹配Numebrs:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^load=/files/[0-9]+/batch-[0-9A-Za-z]+ 
RewriteRule ^/?$ http://secondsite.com/ [L,R=301]

最新更新