Mobile app version of vmapp.org
Login or Join
Frith620

: How do I prevent a rewrite rule from executing for just one subdomain? In the root level .htaccess I have added a condition to rewrite HTTP requests as HTTPS: RewriteEngine On RewriteCond %{HTTPS}

@Frith620

Posted in: #Apache #Htaccess #Http #Https #ModRewrite

In the root level .htaccess I have added a condition to rewrite HTTP requests as HTTPS:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI}

This applies to the main domain and all subdomains. Unfortunately there is still work to do in one of the subdomains in order for it to work with HTTPS, so I would like to insert something into that one's .htaccess file to undo the inherited rewrite rules.

The file must still inherit a lot of other config from the parent domain, so it must only undo that one rewrite rule.

How can I disable this rewrite rule for a particular subdomain?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Frith620

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

If the subdomain points to a subdirectory off the main domain's document root then you can simply include a RewriteEngine On directive in that subdirectory's .htaccess file. However, this will override all the mod_rewrite directives in the parent .htaccess file, which may not be desirable (although "other config from the parent domain" will be inherited).

If you have other mod_rewrite directives in the parent .htaccess that you do want to run then you will need to add a condition to this HTTP to HTTPS rule in the parent .htaccess file that specifically excludes the subdomain.

For example:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^subdomain.
RewriteCond %{HTTPS} !on
RewriteRule ^ %{HTTP_HOST}%{REQUEST_URI} [R=302,L]


Which says... if the host does not start subdomain. and is not https then...

You normally require the L flag on redirects so processing does not continue through the file (if you have more mod_rewrite directives). Also, this shopuld normally be a 301 (permanent) redirect. If this is the case then change the 302 to 301 when you are sure it's working OK. Although maybe best left as a 302 whilst this is being developed.

Also, no need to capture the URL-path (ie. (.*)) if this is not being used in the RewriteRule substitution (or RewriteCond directives).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme