gpt4 book ai didi

apache - 有没有一种方法可以/是否可以在Apache htaccess中进行重写?

转载 作者:行者123 更新时间:2023-12-04 03:12:38 24 4
gpt4 key购买 nike

我想在我的.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错误日志发出了500s的提示:

[错误] [客户端:: 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]

最佳答案

仅包含/排除使用条件比跳过标志可能会更干净(跳过标志可能会造成混淆)。但似乎有一个导致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]

关于apache - 有没有一种方法可以/是否可以在Apache htaccess中进行重写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11906060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com