How to add a bypass rules for my sudomains in my htacess

I have my domaing "www.myserver.com" and I got  customized my ".htaccess" file with the following rewrite rules:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/oculto/larespuesta.php$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www.myserver.com$ [NC]
RewriteRule ^(.*)$ https://www.myserver.com/$1 [L,R=301]

Open in new window


This set of lines allow me:
1.- redirect all calls of "http://" to "https://"
2.- redirect all calls of non "www" to "www"

I wanna know how to bybass of this rules using rewrite rules, subdomains in the same server? I tried with RewriteCond %{HTTP_HOST} !subdomain\.myserver1\.com$ [NC], but after I add that line I need to comment
   RewriteCond %{HTTP_HOST} !^www.myserver.com$ [NC]
   RewriteRule ^(.*)$ https://www.myserver.com/$1 [L,R=301]

Open in new window


Is there a way to add a bypass for my subdomains in my htaccess?
altariamx2003Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Normally this isn't an issue.

Just split your host record Apache config files. Almost ever Linux Distro does this now.

So you'll have one /etc/apache2/sites-available/myserver.com.conf file which contains config for bare domain + www host.

Then another file like /etc/apache2/sites-available/foo.myserver.com.conf containing config for the foo host.

Each host .conf file will contain a ServerName stanza which matches only that one host... like...

<IfModule mod_ssl.c>

   <VirtualHost *:443>

      ServerName  foo.myserver.com

      ... ... ...

   </VirtualHost>

</IfModule>

Open in new window


This approach allows Apache to run faster + be far easier to maintain, than if you somehow... accept all hosts in one config file + then use what you're calling bypass .htaccess rules for subdomains.

Tip: Your example suggests you aren't really using subdomains, instead you're using folder installs for some code.

Folder installs != Subdomains.

Subdomains will take the form of $host.myserver.com where $host is the subdomain name.
altariamx2003Author Commented:
Let me check how to try your solution because we have our server with hostgator all subdmains are created by the cpanel from hostgator

About my question I found the solution by myself

The following code redirect all domains from non-www to www and http to https and excludes all subdomains
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Open in new window


Thx anyway for your time
altariamx2003Author Commented:
The following code redirect all domains from non-www to www and http to https and excludes all subdomains

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
altariamx2003Author Commented:
Thx to David to take time to answer me
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
You're welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
htacess

From novice to tech pro — start learning today.