有没有一种办法的if / else在Apache的htaccess的重写?(Is there a w

2019-06-26 22:56发布

我想在我的.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
}

我有我当前的代码下面,但它抛出500S与我的Apache错误日志抱怨:

[错误] [客户端:: 1]的mod_rewrite:达到内部重定向的最大数量。 假设配置错误。 如果使用neccessary“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]

Answer 1:

它可能是一个少许清洁剂,只是包含/排除使用条件比跳越标志(可以得到一种混乱的阅读)。 但它看起来像有一个重定向循环导致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]


文章来源: Is there a way to if/else a rewrite in Apache htaccess?