I want to redirect user based on their user agent to a specific websites.
Right now my .htaccess file is looking like this:
# 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...
Right now i get a 500 Internal Server Error error when it is entered like this. How to fix it to make it workable?
Best regrards, salexes
Try changing these rules to traditional mod_rewrite rule syntax and keep redirects before default WP rule:
<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>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments