• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2561
  • Last Modified:

apache rewrite rule by HTTP_USER_AGENT

hi experts,

i have the attached rewrite rule. How to change the static /event/ param for each rule depending on the HTTP_USER_AGENT  to /mobileevent/ ?
I mean if somebody connects the page via a mobile device the ac param should be "event" and if somebody connects via Internet Explorer the ac param should be "mobileevent"

i´ve found something like:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla.* [NC]
#RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
#RewriteCond %{HTTP_USER_AGENT} ^MSIE*.*
#RewriteCond %{HTTP_USER_AGENT} ^Windows*.*
RewriteRule ^/$ http://www.domain.de/XY1/ [L]

RewriteCond %{HTTP_USER_AGENT} .*nokia.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*sharp.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*sonyericsson.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*mot-.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*samsung.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*sgh-.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*sagem.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*panasonic.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*symbian.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*symbian*.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*windows.ce*.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*pocket.pc.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*opera.mini.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*midp.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*vodafone.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*pda.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*mda.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*xda.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*sda.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*240x320.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*benq.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*portalmmm.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*blackberry.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*philips.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*safari.* [NC,OR]
RewriteRule ^/([^XY].*)$ /XY2/$1 [R]

in the internet. but how can i combine this code with my rewrite rules.



RewriteEngine On
Options +FollowSymlinks
RewriteBase /
 
ErrorDocument 404 /filenotfound.html
 
 
# Add trailing slash 
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
 
 
#rewrite country city plz kategorie umkreis edf edt p
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=events&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})&edt=(\d{1,2}\-\d{1,2}\-\d{4})&p=(\d{1,3})
RewriteRule ^test\.php$ /events/%1/%2-%3/%4/Umkreis_%5km/%6bis%7/seite%8/? [R=301] 
RewriteRule ^events/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})bis(\d{1,2}\-\d{1,2}\-\d{4})/seite(\d{1,3})/$ test.php?ac=events&country=$1&plz=$2&city=$3&se=$4&uk=$5&edf=$6&edt=$7&p=$8 [NC,L]
 
#rewrite country city plz kategorie umkreis edf edt
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=events&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})&edt=(\d{1,2}\-\d{1,2}\-\d{4})
RewriteRule ^test\.php$ /events/%1/%2-%3/%4/Umkreis_%5km/%6bis%7/? [R=301] 
RewriteRule ^events/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})bis(\d{1,2}\-\d{1,2}\-\d{4})/$ test.php?ac=events&country=$1&plz=$2&city=$3&se=$4&uk=$5&edf=$6&edt=$7 [NC,L]
 
#rewrite country city plz kategorie umkreis edf p
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=events&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})&p=(\d{1,3})
RewriteRule ^test\.php$ /events/%1/%2-%3/%4/Umkreis_%5km/%6/seite%7/? [R=301]
RewriteRule ^events/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})/seite(\d{1,3})/$ test.php?ac=events&country=$1&plz=$2&city=$3&se=$4&uk=$5&edf=$6&p=$7 [NC,L]
 
#rewrite country city plz kategorie umkreis edf
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=events&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})
RewriteRule ^test\.php$ /events/%1/%2-%3/%4/Umkreis_%5km/%6/? [R=301] 
RewriteRule ^events/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})/$ test.php?ac=events&country=$1&plz=$2&city=$3&se=$4&uk=$5&edf=$6 [NC,L]

Open in new window

0
bibabutze
Asked:
bibabutze
1 Solution
 
caterham_wwwCommented:
> I mean if somebody connects the page via a mobile device the ac param should be "event" and if somebody connects via Internet Explorer the ac param should be "mobileevent"

Not vis-a-vis, i.e. mobile device: mobileevent, dor the rest 'event'?
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
 
ErrorDocument 404 /filenotfound.html
 
 
# Add trailing slash (no cond needed in this case, processing is rule -> cond)
RewriteRule ^([^.]+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]
 
# redirects /event/ --> /mobileevent/
RewriteCond %{HTTP_USER_AGENT} ^Mozilla [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Lynx [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^MSIE [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Windows
RewriteRule ^event/(.*)$ /mobileevent/$1 [R,L]
 
# redirects /mobileevent/ --> /event/
RewriteCond %{HTTP_USER_AGENT} nokia [NC,OR]
RewriteCond %{HTTP_USER_AGENT} sharp [NC,OR]
RewriteCond %{HTTP_USER_AGENT} sonyericsson [NC,OR]
RewriteCond %{HTTP_USER_AGENT} mot- [NC,OR]
RewriteCond %{HTTP_USER_AGENT} samsung [NC,OR]
RewriteCond %{HTTP_USER_AGENT} sgh- [NC,OR]
RewriteCond %{HTTP_USER_AGENT} sagem [NC,OR]
RewriteCond %{HTTP_USER_AGENT} panasonic [NC,OR]
RewriteCond %{HTTP_USER_AGENT} symbian [NC,OR]
RewriteCond %{HTTP_USER_AGENT} symbian [NC,OR]
RewriteCond %{HTTP_USER_AGENT} windows\.ce [NC,OR]
RewriteCond %{HTTP_USER_AGENT} pocket\.pc [NC,OR]
RewriteCond %{HTTP_USER_AGENT} opera\.mini [NC,OR]
RewriteCond %{HTTP_USER_AGENT} midp [NC,OR]
RewriteCond %{HTTP_USER_AGENT} vodafone [NC,OR]
RewriteCond %{HTTP_USER_AGENT} pda [NC,OR]
RewriteCond %{HTTP_USER_AGENT} mda [NC,OR]
RewriteCond %{HTTP_USER_AGENT} xda [NC,OR]
RewriteCond %{HTTP_USER_AGENT} sda [NC,OR]
RewriteCond %{HTTP_USER_AGENT} 240x320 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} benq [NC,OR]
RewriteCond %{HTTP_USER_AGENT} portalmmm [NC,OR]
RewriteCond %{HTTP_USER_AGENT} blackberry [NC,OR]
RewriteCond %{HTTP_USER_AGENT} philips [NC,OR]
RewriteCond %{HTTP_USER_AGENT} safari
RewriteRule ^mobileevent/(.*)$ /event/$1 [R,L] 
 
#rewrite country city plz kategorie umkreis edf edt p
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=(events|mobileevent)&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})&edt=(\d{1,2}\-\d{1,2}\-\d{4})&p=(\d{1,3})
RewriteRule ^test\.php$ /%1/%2/%3-%4/%5/Umkreis_%6km/%7bis%8/seite%9/? [R=301] 
RewriteRule ^(events|mobileevent)/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})bis(\d{1,2}\-\d{1,2}\-\d{4})/seite(\d{1,3})/$ test.php?ac=$1&country=$2&plz=$3&city=$4&se=$5&uk=$6&edf=$7&edt=$8&p=$9 [NC,L]
 
#rewrite country city plz kategorie umkreis edf edt
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=(events|mobileevent)&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})&edt=(\d{1,2}\-\d{1,2}\-\d{4})
RewriteRule ^test\.php$ /%1/%2/%3-%4/%5/Umkreis_%6km/%7bis%8/? [R=301] 
RewriteRule ^(events|mobileevent)/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})bis(\d{1,2}\-\d{1,2}\-\d{4})/$ test.php?ac=$1&country=$2&plz=$3&city=$4&se=$5&uk=$6&edf=$7&edt=$8 [NC,L]
 
#rewrite country city plz kategorie umkreis edf p
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=(events|mobileevent)&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})&p=(\d{1,3})
RewriteRule ^test\.php$ /%1/%2/%3-%4/%5/Umkreis_%6km/%7/seite%8/? [R=301]
RewriteRule ^(events|mobileevent)/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})/seite(\d{1,3})/$ test.php?ac=$1&country=$2&plz=$3&city=$4&se=$5&uk=$6&edf=$7&p=$8 [NC,L]
 
#rewrite country city plz kategorie umkreis edf
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/test\.php\?ac=(events|mobileevent)&country=(\w{2})&plz=(\d{4,5})&city=([\w+\s\_\-]+)&se=(\w+)&uk=(\d{1,3})&edf=(\d{1,2}\-\d{1,2}\-\d{4})
RewriteRule ^test\.php$ /%1/%2/%3-%4/%5/Umkreis_%6km/%7/? [R=301] 
RewriteRule ^(events|mobileevent)/(\w{2})/(\d{4,5})-([\w+\s\_\-]+)/(\w+)/Umkreis_(\d{1,3})km/(\d{1,2}\-\d{1,2}\-\d{4})/$ test.php?ac=$1&country=$2&plz=$3&city=$4&se=$5&uk=$6&edf=$7 [NC,L]

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now