📱
Security

.htaccess redirect hack: mobile visitors are sent to another site

20.11.2026
← All articles

This problem confuses site owners. Customers say the site "jumps to some advertising page", while the owner opens it on a desktop and sees nothing wrong. The reason is that the attacker added rules to .htaccess that fire only under certain conditions: usually for visitors on a phone who arrive from a search engine. Someone typing the address directly or browsing from a desktop sees the normal site.

How the rules work

On Apache, .htaccess sets per-directory configuration, including rewrite and redirect rules via mod_rewrite. WordPress uses it for pretty permalinks, so a few rules are normal. The attacker adds conditions on request headers: if the User-Agent looks mobile and the referer is Google or Yandex, the visitor is redirected. A simplified example of such rules, which in real cases are often buried among blank lines:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (android|iphone|mobile) [NC]
RewriteCond %{HTTP_REFERER} (google|yandex|bing) [NC]
RewriteRule ^(.*)$ https://spam-sayt.example/ [R=302,L]

Example: a dental clinic in Tashkent

A private dental clinic in Tashkent saw online bookings drop sharply. Patients said the site "took them somewhere else", yet it opened correctly on the clinic's computer. Searching for the clinic on a phone and tapping the result opened a prize-draw page. The root .htaccess had rules like the ones above, and another copy sat in wp-content/uploads. Both files had been modified five days earlier, which helped date the compromise.

Confirming the redirect with curl

curl -sI https://example.uz/
curl -sI -A "Mozilla/5.0 (Linux; Android 13; Mobile)" -e "https://www.google.com/" https://example.uz/

If the first request returns 200 and the second returns 301 or 302 with a foreign Location, the redirect is confirmed. Some malware redirects only on the first visit and then sets a cookie; that is usually done in PHP or JavaScript, so a clean .htaccess does not rule out infection.

Finding and cleaning the files

find . -name ".htaccess" -exec grep -lE "HTTP_USER_AGENT|HTTP_REFERER" {} +
find . -name ".htaccess" -mtime -14 -ls

Review every match, since some cache and security plugins use similar conditions legitimately. For a standard WordPress site, save a copy of the old file and replace the root .htaccess with the default block:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Restore legitimate rules such as HTTPS redirects manually, and delete stray .htaccess files in subfolders unless they clearly belong to a plugin.

Why it keeps coming back

If the file is modified again the next day, it is a symptom, not the cause. A webshell or injected code is still on the site, sometimes triggered by a cron job.

  1. Review recently changed PHP files: find . -name "*.php" -mtime -14.
  2. Check for PHP in uploads: find wp-content/uploads -name "*.php".
  3. Verify core files: wp core verify-checksums.
  4. Inspect scheduled tasks: crontab -l.
  5. Change hosting, FTP, database and administrator passwords after cleanup.

Setting chmod 444 .htaccess slows rewrites but is not real protection, because a script running as the file owner can change the permissions back. Note that Nginx ignores .htaccess; on such setups the redirect is done in PHP or in JavaScript stored in the database. sayt.uz hosting is managed through ISPmanager, and on typical WordPress sites .htaccess rules apply. After cleanup, check Security issues in Google Search Console and request a review; for complex cases open a ticket from the sayt.uz cabinet.

Related articles

🚪 Finding a Backdoor in WordPress: 10 Clear Signs and the Commands to Check 🐞 APP_DEBUG=true: The Dangerous Mistake Left on Production Servers 🛡️ Securing a DLE Site: Licensing, the Admin Panel and the uploads Folder 🖱️ Clickjacking: protecting your site with X-Frame-Options and CSP
🌐 Language
🇺🇿 O'zbek 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓