1

我有一个 302 重定向设置指向一个文件夹,但这应该只影响非移动用户。

RedirectMatch 302 ^/$ /my-folder-name/

为了将此限制为桌面用户,我试图通过用户代理过滤掉,如下所示:

RewriteCond %{HTTP_USER_AGENT} !(iphone|ipod|android|symbian|windows\ phone|blackberry|iemobile|opera\ mobile|palmos|webos|googlebot-mobile)   [NC]
RedirectMatch 302 ^/$ /my-folder-name/

但这不起作用。我应该使用RewriteRule而不是RedirectMatch吗?我试过但无法找出正确的语法 - 任何帮助将不胜感激。

4

2 回答 2

3

知道了。RedirectMatch不受RewriteCond. 我最终使用:

RewriteCond %{HTTP_USER_AGENT} !(iphone|ipod|android|symbian|windows\ phone|blackberry|iemobile|opera\ mobile|palmos|webos|googlebot-mobile)   [NC]
RewriteRule ^$ /my-folder-name/ [R=302,L]
于 2013-07-30T17:52:43.733 回答
0

你可以把它放在虚拟主机中:

  <If "%{HTTP_HOST} == 'thedomain.com' || %{HTTP_HOST} == 'www.thedomain.com'">
  Redirect "/" "https://thedomain.com/"
  </If>

进一步参考:

https://httpd.apache.org/docs/2.4/rewrite/remapping.html

https://httpd.apache.org/docs/2.4/mod/core.html#if

于 2019-06-06T03:58:08.397 回答