从RewriteCond中排除子域

时间:2013-05-29 23:40:53

标签: apache mod-rewrite url-rewriting

我正在Apache上运行Zend Framework(PHP)应用程序。您可能知道,此框架要求将所有URL路由到public/index.php(前端控制器模式)。因此,我已将以下规则添加到.htaccess目录中的public_html

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]

在DirectAdmin中,我创建了一个名为newsletter的子域,默认情况下(我猜)会期望其文件驻留在public_html/newsletter中。但是,当我访问newsletter.mydomain.com/somefile.html时,.htaccess规则会将此重定向到http://www.newsletter.mydomain.com//public/newsletter/

如何从.htaccess规则中排除我的子域?

1 个答案:

答案 0 :(得分:3)

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]