有没有一种方法可以在Apache htaccess中进行重写?

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

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:

[error] [client :: 1] mod_rewrite:达到的最大内部redirect数目。 假设configuration错误。 如果需要,使用“RewriteOptions MaxRedirects”来增加限制。引用:

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

 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] 

仅仅包含/排除使用条件比跳过标志(可能会让人困惑的阅读)更清洁一点。 但它看起来像有一个重定向循环导致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]