Freek Vanraes
Freek Vanraes

Reputation: 227

Excluding a subdomain from RewriteCond

I'm running a Zend Framework (PHP) application on Apache. As you might know, this framework requires all URLs to be routed to public/index.php (front controller pattern). Therefore, i've added the following rules to the .htaccess in the public_html directory:

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

# rewrite non-www url's
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

In DirectAdmin, I've created a subdomain called newsletter, which (by default i guess) expects its files to reside in public_html/newsletter. However, when i visit newsletter.mydomain.com/somefile.html the .htaccess rules redirect this to http://www.newsletter.mydomain.com//public/newsletter/.

How can I exclude my subdomain from the .htaccess rules ?

Upvotes: 1

Views: 3766

Answers (1)

Gerben
Gerben

Reputation: 16825

RewriteEngine On

# don't apply any rewrites to the domain newsletter.mydomain.com
RewriteCond %{HTTP_HOST} ^newsletter\.mydomain\.com$
RewriteRule .* - [L]

# rewrite non-www url's
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

#shouldn't be needed!
RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

Upvotes: 3

Related Questions