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

  • SEARCH
  • Home
  • 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 9150229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:35:06+00:00 2026-06-17T11:35:06+00:00

Having a difficult time finding the combination to satisfy the following 3 conditions. What

  • 0

Having a difficult time finding the combination to satisfy the following 3 conditions. What Rewrite rules and conditions will accomplish the conditions? (I’ve already been surprised by the rules not working.)

  1. www stripped from all requests
  2. https for all requests to primary
  3. http for all requests to subdomain (in subfolder of main site) subdomain.com

htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.primary\.mobi [NC,OR]
RewriteCond %{HTTP_HOST} ^primary\.mobi [NC,OR]
RewriteCond %{HTTP_HOST} !^(www\.)?subdomain\.com [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

The above do not strip www and send http://www.subdomain to https.

Explanations welcomed. Trying to understand the apache mod_rewrite manual page and have tried several methods without success.

  • 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-17T11:35:07+00:00Added an answer on June 17, 2026 at 11:35 am

    You can capture the domain and use it in your RewriteRule. HTTP_REQUEST is not available in the substitution part, but only in RewriteCond directives.

    I’m not sure, but you can try to split this into two .htaccess files. This one goes into the main directory

    RewriteEngine On
    
    # remove www. from HTTPS requests
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^www\.(primary\.mobi)$ [NC]
    RewriteRule .* https://%1/$0 [R,L]
    
    # redirect HTTP requests to HTTPS
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(primary\.mobi)$ [NC]
    RewriteRule .* https://%1/$0 [R,L]
    

    and this is for the .htaccess in the subdomain folder

    RewriteEngine On
    
    # remove www. from HTTP requests
    RewriteCond %{HTTP_HOST} ^www\.(subdomain\.com)$ [NC]
    RewriteRule .* http://%1/$0 [R,L]
    
    # redirect HTTPS requests to HTTP
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(subdomain\.com)$ [NC]
    RewriteRule .* http://%1/$0 [R,L]
    

    Test your rules without 301, because the browser caches 301 results and makes testing much harder. Add R=301 not until you’re satisfied with the rules.

    In Canonical Hostnames are some alternatives described, especially the first one, using virtual hosts, looks promising

    <VirtualHost *:80>
        ServerName www.primary.mobi
        Redirect / https://primary.mobi/
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName primary.mobi
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName www.subdomain.com
        Redirect / http://subdomain.com/
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName subdomain.com
    </VirtualHost>
    

    I don’t know, if this is feasible for you, but you might try.

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

Sidebar

Related Questions

I seem to be having a difficult time finding a plugin that will zoom
I'm having a difficult time finding any resources that describe good UI patterns for
I'm having a difficult time finding information on how to get RavenDB to work
I'm having a very difficult time finding many resources available for Flash Builder 4.6
I'm having a difficult time finding specific info for my case. I'd like to
I'm having a difficult time finding definitive information on this. If I have a
I'm having a difficult time finding how to do true data binding for UITableViews.
I'm having a difficult time finding any decent documentation for packaging on OSX. My
I'm having a difficult time finding the right keywords to search on for this.
So, I'm having a difficult time (no pun intended) finding if an NSDate is

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.