10

我想在我的 .htaccess 文件中创建以下结构:

If (SITE A DOMAIN or SITE A SUBDOMAIN) {  
   Rewrite this specific way ->  /index.php/$1 
} else {
   Rewrite this specific way ->  /directory/www/index.php/$1
}

我在下面有我当前的代码,但是我的 Apache 错误日志抱怨它抛出了 500 秒:

[错误] [客户端 ::1] mod_rewrite:达到内部重定向的最大数量。假设配置错误。如有必要,请使用“RewriteOptions MaxRedirects”来增加限制。,referer:

我究竟做错了什么?谢谢!

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|blog)

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^ example\.com$
RewriteRule .? - [S=1]
RewriteRule ^(.*)$ /directory/www/index.php/$1 [L]
RewriteRule .? - [S=1]
RewriteRule ^(.*)$ /index.php/$1 [L]
4

1 回答 1

17

仅包含/排除使用条件可能比跳过标志更简洁(这可能会让人感到困惑)。但看起来有一个重定向循环导致 500。试试这个:

# If (SITE A DOMAIN or SITE A SUBDOMAIN) 
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# make sure we haven't already rewritten this URI
RewriteCond %{REQUEST_URI} !/directory/www/index.php
# don't rewrite if the resource already exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite
RewriteRule ^(.*)$ /directory/www/index.php/$1 [L]

# IF !(SITE A DOMAIN or SITE A SUBDOMAIN) 
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
# make sure we haven't already rewritten this URI
RewriteCond %{REQUEST_URI} !/index.php
# don't rewrite if the resource already exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite
RewriteRule ^(.*)$ /index.php/$1 [L]
于 2012-08-10T18:32:52.453 回答