.htaccess 代码只影响主域

.htaccess code to affect main domain only

我有两个域。 1) 主要 2) 子域。 .htaccess 文件中的这段代码给我带来了问题。

# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !=/favicon.ico
# RewriteRule ^ index.php [L]

照原样,两个站点上的一切看起来都很完美,并且对最终用户来说运行顺畅。但是,此代码意味着我们无法在主域上进行任何管理员更改(页面编辑、创建内容等)。

如果我 "uncomment" 最后 4 行,我可以对主域进行更改,但子域不再指向相应的主题文件。

是否可以 "uncomment" 底部 4 行并且只影响主域?

你可以使用这个.htaccess:

RewriteCond %{HTTP_HOST} !^subdomain\.example.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

排除子域。