有没有办法在 Apache htaccess 中进行 if/else 重写? [英] Is there a way to if/else a rewrite in Apache htaccess?
本文介绍了有没有办法在 Apache htaccess 中进行 if/else 重写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的 .htaccess 文件中创建以下结构:
I want to create the following structure in my .htaccess file:
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
}
我在下面有我当前的代码,但它抛出了 500 秒,我的 Apache 错误日志抱怨:
I have my current code below, but it's throwing 500s with my Apache error logs whining about:
[error] [client ::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]
推荐答案
与跳过标志相比,仅使用条件包含/排除可能会更简洁一些(这可能会使阅读有些混乱).但看起来有一个重定向循环导致 500.试试这个:
It may be a little cleaner to just include/exclude using conditions than the skip flags (which can get kind of confusing to read). But it looks like there's a redirect loop causing the 500. Try this:
# 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]
这篇关于有没有办法在 Apache htaccess 中进行 if/else 重写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文