How to Redirect Desktop Visitors to Another Page Using .htaccess

 

Summary:

This guide shows you how to use a simple .htaccess code that redirects desktop visitors to another page (for example, a “desktop not supported” notice), while mobile visitors (Android, iPhone, iPad, etc.) can still access your main website normally.

 

 

---

 

Step 1: Open or create your .htaccess file

 

1. Login to cPanel → File Manager.

 

 

2. Navigate to your website’s root directory (usually public_html or the document root of your addon domain/subdomain).

 

 

3. Locate the .htaccess file. If it doesn’t exist, create a new file named .htaccess.

 

 

 

 

---

 

Step 2: Add the redirect code

 

Paste the following code at the very top of your .htaccess file:

######

# Redirect desktop users to another page

RewriteEngine On

 

# Detect common mobile devices

RewriteCond %{HTTP_USER_AGENT} "android|iphone|ipad|ipod|blackberry|windows phone|opera mini|mobile" [NC]

 

# If mobile, allow normal site

RewriteRule ^ - [L]

 

# Otherwise (desktop), redirect to another page

RewriteRule ^ https://yourdomain.com/desktop-not-supported [L,R=302]

######

 

---

 

Step 3: Customize the redirect

 

Replace:

 

https://yourdomain.com/desktop-not-supported

 

with the full URL where you want to send desktop visitors.

For example:

 

A special landing page (https://example.com/desktop.html)

 

Another domain (https://m.example.com)

 

 

 

 

---

 

Step 4: Save and test

 

1. Save the .htaccess file.

 

 

2. Test your site on both desktop and mobile:

 

On desktop, you should be redirected to the page you set.

 

On mobile, you should see your normal site.

 

 

 

 

 

---

 

Example use case

 

Let’s say you want desktop visitors to go to https://yourdomain.com/notice.html while mobile visitors still see the main homepage.

Your .htaccess should look like this:

 

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} "android|iphone|ipad|ipod|blackberry|windows phone|opera mini|mobile" [NC]

RewriteRule ^ - [L]

RewriteRule ^ https://yourdomain.com/notice.html [L,R=302]

 

 

---

 

How to remove later

 

To stop redirecting desktops, simply delete the code block you added from .htaccess, then save the file.

 

 

---

 

⚠️ Note:

 

If you use WordPress, place this code above the # BEGIN WordPress section.

 

If you use caching/CDN (like LiteSpeed Cache or Cloudflare), clear cache after editing .htaccess.

 

 

 

---

 

???? Would you like me to also create a “copy-paste rea

dy” version formatted with <pre><code> blocks (so your WHMCS KB shows the code neatly, without WHMCS escaping it)?

 

Hjalp dette svar dig? 2 Kunder som kunne bruge dette svar (2 Stem)