Rewrite rule for user agent with mod_rewrite

前端 未结 2 516
小蘑菇
小蘑菇 2020-12-18 00:38

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_USE         


        
相关标签:
2条回答
  • 2020-12-18 00:45

    There are 2 bugs:

    First:

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

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

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

    Second:

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

    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]
    
    0 讨论(0)
  • 2020-12-18 00:48

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

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

    0 讨论(0)
提交回复
热议问题