gpt4 book ai didi

.htaccess - 从 htaccess 重定向中排除子域

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:50 24 4
gpt4 key购买 nike

我在提交这个线程之前搜索了 stackoverflow,但我没有运气:-S

我的网站有一个复杂的 .htaccess 文件,如下所示:

这部分用于重定向(X.2nate dot com --> 2nate dot com/api/x)并且运行良好

########### API Redirection Section ##########

RewriteEngine On
# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.2nate\.com$ [NC]
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail|charge)$ [NC]
# Redirect all requests to the original url /blog
RewriteRule ^.*$ https://2nate.com/api/%1 [L]

这部分用于将非 SSL 请求重定向到 SSL 协议(protocol):

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

这部分用于使用 WWW 重定向到非 WWW 地址:

RewriteCond %{HTTP_HOST} ^www\.2nate\.com$
RewriteRule ^/?$ "http\:\/\/2nate\.com\/" [R=301,L]

问题是:

当我尝试访问“charge”dot mywebsite dot com(charge 是我的主机中的一个真正的子域)时,我无法访问相关页面,它正在重定向到主页!

我认为这部分有问题:

RewriteCond %{HTTP_HOST} ^www\.2nate\.com$
RewriteRule ^/?$ "http\:\/\/2nate\.com\/" [R=301,L]

因为当我删除这部分时,一切正常(除了重定向到非 WWW)。

感谢任何帮助。

最佳答案

问题实际上是这个规则:

RewriteRule ^.*$ https://2nate.com/api/%1 [L]

因为您在目标 URL 中使用了 http://,所以它不是静默重写,而是会变成外部重定向。

让你的 .htaccess 像这样:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTP_HOST} ^www\.2nate\.com$
RewriteRule ^ http://2nate.com%{REQUEST_URI} [R=301,L,NE]

# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.2nate\.com$ [NC]
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail|charge)$ [NC]
# Redirect all requests to the original url /blog
RewriteRule ^.*$ /api/%1 [L]

关于.htaccess - 从 htaccess 重定向中排除子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25581963/

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