1

我在 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]

newsletter在DirectAdmin中,我创建了一个名为public_html/newsletter. 但是,当我访问规则时,将newsletter.mydomain.com/somefile.html.htaccess重定向到http://www.newsletter.mydomain.com//public/newsletter/.

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

4

1 回答 1

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]
于 2013-05-31T13:34:14.190 回答