Apache .htaccess 301使用回退重定向特定URL

Apache .htaccess 301使用回退重定向特定URL,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我正在迁移一个域 我有一些URL,我需要将它们重定向到一个特定的页面,但其他一切都可能是一个全面的后备。我还需要维护查询字符串 例如: 手动URL: http://example.com/i-am-manual-redirect => https://example2.com/this-is-not-the-same-URL http://example.com/i-am-manual-redirect2 => https://example2.com/somew

我正在迁移一个域

我有一些URL,我需要将它们重定向到一个特定的页面,但其他一切都可能是一个全面的后备。我还需要维护查询字符串

例如:

手动URL:

http://example.com/i-am-manual-redirect   =>    https://example2.com/this-is-not-the-same-URL
http://example.com/i-am-manual-redirect2   =>    https://example2.com/somewhere-else
然后是其他所有事情的后备方案:

http://example.com/same   =>    https://example2.com/same
http://example.com/blah   =>    https://example2.com/blah
目前有:

# Manual Redirects
RedirectMatch 301 ^/i-am-manual-redirect https://example2.com/this-is-not-the-same-URL
RedirectMatch 301 ^/i-am-manual-redirect2 https://example2.com/somewhere-else

# Fallback
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example2.com/$1 [L,R=301,NC]

但是,每当我添加回退时,手动重定向都不起作用。

您需要阻止重写规则处理手动重定向,或者使用mod_rewrite完成所有操作。我想,修改是先处理的。或者全部更改为使用mod_rewrite。以下是您的最新情况:

# Manual Redirects
Redirect 301 /i-am-manual-redirect https://example2.com/this-is-not-the-same-URL
Redirect 301 /i-am-manual-redirect2 https://example2.com/somewhere-else

# Fallback
RewriteCond %{REQUEST_URI} !=/i-am-manual-redirect
RewriteCond %{REQUEST_URI} !=/i-am-manual-redirect-2
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example2.com/$1 [L,R=301]
你知道你的前两个去https://和你的回退到http://吗?只是检查一下

规则上不需要NC,因为正则表达式中未指定任何字符


在指定完整URL时无需使用RedirectMatch,因为查询字符串不匹配。在这两种情况下,它都是按您的意愿传递的。

您是否尝试过将回退放在第一位?在我看来,该文件将自上而下读取,因此回退优先,因为它在手动重定向之后。我可能错了,目前无法测试,但值得一试。