Link to home
Start Free TrialLog in
Avatar of altariamx2003
altariamx2003Flag for Mexico

asked on

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?
Avatar of David Favor
David Favor
Flag of United States of America image

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.
Avatar of altariamx2003

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of altariamx2003
altariamx2003
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thx to David to take time to answer me
You're welcome!