与mod_rewrite的用户代理重写规则 [英] Rewrite rule for user agent with mod_rewrite

查看:150
本文介绍了与mod_rewrite的用户代理重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个站点的所有请求从一个特定的用户代理到一个子域重定向。我的规则如下:

I'm trying to redirect all requests to a domain from a particular user-agent to a subdomain. My rule is as follows:

RewriteEngine  on
RewriteCond %{HTTP_USER_AGENT}  ^Test Agent/(.*)$ // <-- Line 4
RewriteRule ^(.*)$         https://test.domain.com/$1          [L,302]

但是,所有启动Web服务器时,我得到的是:

But all I get when starting the web server is:

Syntax error on line 4 of /var/www/misafe/internal/misafe-old.conf:
RewriteCond: bad flag delimiters

这看起来不错给我,但我显然缺少的东西,错误是没有帮助很多。任何想法?

It looks OK to me but I'm obviously missing something and the error is not helping much. Any ideas?

谢谢,
Ĵ

推荐答案

有2错误:

首先:

RewriteCond %{HTTP_USER_AGENT}  ^Test Agent/(.*)$

您需要逃避常规的前pression模式的空间和斜杠。

You need to escape the space and forward slash in your regular expression pattern.

RewriteCond %{HTTP_USER_AGENT}  ^Test\ Agent\/(.*)$

二:

RewriteRule ^(.*)$         https://test.domain.com/$1          [L,302]

302重定向HTTP状态code,但你没有指定要重定向。

302 is a redirect HTTP status code, but you didn't specify that you are redirecting.

RewriteRule ^(.*)$         https://test.domain.com/$1          [L,R=302]

这篇关于与mod_rewrite的用户代理重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆