我想根据用户代理将用户重定向到特定网站。
现在我的.htaccess文件看起来像这样:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_USER_AGENT} opera
RewriteCond %{QUERY_STRING} articleid=(?:[0-9]{1,3}|1000)
<If "%{QUERY_STRING} == 'articleid=001'">
RewriteRule ^$ http://m.example.com/ [L,R=302]
</If>
<ElseIf "%{QUERY_STRING} == 'articleid=002'">
RewriteRule ^$ http://m.example2.com/ [L,R=302]
</ElseIf>
<ElseIf "%{QUERY_STRING} == 'articleid=003'">
RewriteRule ^$ http://m.example3.com/ [L,R=302]
</ElseIf>
<ElseIf "%{QUERY_STRING} == 'articleid=004'">
RewriteRule ^$ http://m.example4.com/ [L,R=302]
</ElseIf>
etc...
现在我输入500内部服务器错误时会出现这样的错误。如何修复它以使其可行?
最佳注册人, salexes
答案 0 :(得分:2)
尝试将这些规则更改为传统的mod_rewrite规则语法,并在默认WP规则之前保留重定向:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} opera
RewriteCond %{QUERY_STRING} (^|&)articleid=articleid=001(&|$) [NC]
RewriteRule ^$ http://m.example.com/? [L,R=302]
RewriteCond %{HTTP_USER_AGENT} opera
RewriteCond %{QUERY_STRING} (^|&)articleid=articleid=002(&|$) [NC]
RewriteRule ^$ http://m.example2.com/? [L,R=302]
RewriteCond %{HTTP_USER_AGENT} opera
RewriteCond %{QUERY_STRING} (^|&)articleid=articleid=003(&|$) [NC]
RewriteRule ^$ http://m.example3.com/? [L,R=302]
RewriteCond %{HTTP_USER_AGENT} opera
RewriteCond %{QUERY_STRING} (^|&)articleid=articleid=004(&|$) [NC]
RewriteRule ^$ http://m.example4.com/? [L,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>