2015-08-09 199 views
1

我想根据用户代理将用户重定向到特定网站。.htaccess - 500内部服务器错误

现在我的.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内部服务器错误错误。如何解决它,使其可行?

最佳regrards, salexes

+0

的Apache的版本什您使用的是? – starkeen

+0

apache/2.2.31(Unix)mod_ssl/2.2.31在centos上6.7 我刚刚读过那个elseif等仅仅是2.4的可用。是否有2.4 apache版本可用于centos 6.7? – Salexes

+1

如果elseif指令在Apache 2.4及更高版本中可用,则不在2.2中。 – starkeen

回答

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>