0

My .htaccess mobile redirect code used to work. Now it stopped working. Does anyone know why? Here's the code:

rewritecond %{HTTP_HOST} ^www.anumberoneanimalandpestcontrol.com$ [OR]
rewritecond %{HTTP_HOST} ^anumberoneanimalandpestcontrol.com$
rewritecond %{HTTP:x-wap-profile} !^$ [OR]
rewritecond %{HTTPS:Profile}       !^$ [OR]
RewriteCond %{QUERY_STRING} !^desktop
# if the browser accepts these mime-types, it's definitely mobile, or pretending to be
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]

# a bunch of user agent tests
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]

rewriterule ^$ http\:\/\/anumberoneanimalandpestcontrol\.com\/pest-control-baltimore-mobile\.html[R=301,L]
  • 4
    What do you mean by "stopped working" exactly? Do you get an error? Or literally, it's just "stopped working"?! There are some obvious errors (missing spaces before the flags) that will break the redirect - but that will have always broken the redirect? Also, what URLs are you requesting? Your RewriteRule only redirects requests for the document root. – DocRoot Mar 17 '16 at 13:42
  • It stopped redirecting. However, I have a sub-problem. When I test the site on Mobile Friendly Test, I get a response "failed to fetch the requested URL. I had a malware problem on the site, which I have cleared up, but that's not helping. As soon as I solve this problem I can try the various suggestions that people have made about altering the code. – boruchf Mar 27 '16 at 18:26
1

I'd remove at least lines 3 through 7 because you're trying to detect very old phones with very small screens, and most mobile phones support standard HTML.

As for your rewrite rule, change:

rewriterule ^$ http\:\/\/anumberoneanimalandpestcontrol\.com\/pest-control-baltimore-mobile\.html[R=301,L]

to:

RewriteRule ^$ http://anumberoneanimalandpestcontrol.com/pest-control-baltimore-mobile.html [R=301,L]

There always needs to be one space before the first square bracket when it starts a set of RewriteRule/RewriteCond parameters such as [R=301,L].

I would suggest ditching most of your code except for lines 1, 2, and the last line and in between line 2 and the last line, add all the RewriteCond's in the apache code that you download from following this URL:

http://detectmobilebrowsers.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.