.htaccess rewrite conditition ignore subdomain

My main domain is a WordPress blog, and the .htaccess rewrite for it is as follows…

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
  </IfModule>

This works great, but I have a subdomain in that same directory, and am using this rewrite for it….

Read More
    RewriteCond %{SERVER_PORT} ^443$
    RewriteCond %{HTTP_HOST} ^my.domain.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/my/
    RewriteRule ^(.*) /my/$1

That’s for my wildcard SSL certificate. This works great, but if the location doesn’t exist in the subdomain I get wordpress’s error page. I need the wordpress rewrite to ignore the “my” subdomain. How can I do that?

I was thinking something like….

  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^my.domain.com$ 
    RewriteRule . /index.php [L]
  </IfModule>

But that doesn’t work, also tried this….

  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^my.domain.com - [L,NC]
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
  </IfModule>

Any ideas?

Related posts

Leave a Reply

1 comment

  1. You should probably ignore the domain by adding a condition on the server name.

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{SERVER_NAME} !^my.domain.com
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
    

    Also, a thing I struggled with some time ago, try changing the htaccess of the subdomain to

    RewriteBase /my 
    

    if “my” would be the directory it lives in.