Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:17:06+00:00 2026-06-07T17:17:06+00:00

I’ve been googling the hell out of the problem I’m having and so far

  • 0

I’ve been googling the hell out of the problem I’m having and so far I have found nothing that works.

What I have is a Drupal multi-site installation that I’m trying to setup redirects for mobile on. To start I have 10 domains that have only one common string, www. What I want is to check if the device viewing the site is mobile (I’m using AMF to successfully do this) and make sure that the visitor is not already on the mobile version which will be m.domain.tld. If all is good then I need to redirect the user to the mobile subdomain.

Doing this per domain works using the following:

RewriteCond %{ENV:AMF_DEVICE_IS_MOBILE} ^true$
RewriteCond %{ENV:AMF_DEVICE_IS_TABLET} !^true$
RewriteCond %{HTTP_HOST} !^[m.]+mysite.com$
RewriteRule (.*) http://m.mysite.com/$1 [R=301,L]

I do not, however, want to have 10 of those blocks (1 for each domain) nor do I want to have to create another block every time we create a new website.

I have read that you can use () in the RewriteCond patterns to make a var out of the matching pattern. Unfortunately I don’t think I’m making my pattern properly or something because when I try the following it redirects to m. followed by whatever the request uri is.

I’m leaving out the AMF conditions for brevity.

RewriteCond %{HTTP_HOST} !^[m.]+([^.]\.[com|net|org])$
RewriteRule (.*) http://m.%1/$1 [R=301,L]

From what I read, the %1 should match my pattern from the RewriteCond but it isn’t matching anything. That makes me think my pattern is wrong. I’ve tried changing ([^.].[com|net|org]) to (.*) but get the same issue where it just redirects to m..

Am I right in assuming my pattern is wrong and if so what should I be using? Is what I’m trying to do even possible?

To be clear, my domains are in the form of:

http://www.domain.com

http://www.anotherdomain.net

somedomain.org

http://www.maybeanotherdomain.com

In my examples I have the flag R=301 but in testing I’m leaving that out and have to clear a lot of data from the browser each time I test to make sure I’m picking up the new rule.

Thanks in advance for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:17:08+00:00Added an answer on June 7, 2026 at 5:17 pm

    You can’t backreference a not match (!), but you can separate the condition into 2 matches against the %{HTTP_HOST} variable:

    RewriteCond %{HTTP_HOST} !^m\.
    RewriteCond %{HTTP_HOST} ([^\.]+)\.(com|net|org)$ [NC]
    RewriteRule (.*) http://m.%1.%2/$1 [R=301,L]
    

    You may need to tailor the ([^\.]+)\. bit to suit your needs, this expression will only match the “domain” part of “www.domain.com”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.