2012-08-10 43 views
9

我想在我的.htaccess文件中創建的結構如下:有沒有辦法在Apache htaccess中重寫if/else?

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 
} 

下面我有我當前的代碼,但它拋出500S與我的Apache錯誤日誌抱怨:

[錯誤] [客戶端:: 1] mod_rewrite:達到的內部重定向的最大數量。假設配置錯誤。如果需要,使用'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] 

回答

15

只是使用條件而不是跳過標誌(可能會引起混淆)。但它看起來像有一個重定向循環導致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] 
+0

謝謝,工作! – 2012-08-10 20:32:29

相關問題