【问题标题】:Redirect subdomain to domain and keep everything after the URL将子域重定向到域并保留 URL 之后的所有内容
【发布时间】:2016-06-10 09:23:29
【问题描述】:

我需要重定向我的子域

http://sub.domain.com

http://domainB.com/news

我在 htaccess 中测试了各种可能性,但没有任何结果。

此代码运行良好,但从域重定向,而不是从子域...

RewriteCond %{HTTP_HOST} ^domain.com$ 
RewriteRule ^(.*) https://subdomain.domainB.com/$1 [P]

此代码将 domain.com 重定向到

https://subdomain.domainB.com

并在地址栏中保留 domain.com 并正常工作。我想要子域到 subdomainB。

我需要帮助。

提前致谢;)

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-redirection


    【解决方案1】:

    您需要在 RewriteCond 中匹配子域。

    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ 
    RewriteRule ^(.*)$ https://subdomain.domainB.com/$1 [P]
    

    【讨论】:

    • 将此代码放在文档根目录中?还是在子域文件夹中?
    • 代码没问题,代码中没有什么会导致500错误。请检查您的错误日志以获取有关错误的更多信息
    • 我把代码 htaccess 放在哪里了?在 / 文件夹或子域文件夹中?谢谢
    • 然后,你必须把它放在 /subdomain/.htaccess
    • 好的,我要去测试了
    【解决方案2】:

    除了starkeen 的回答之外,在使用SSLEngine on 时,您应该在Apache 设置中添加SSLProxyEngine On,否则会引发内部服务器错误(500): p>

    SSLEngine on
    SSLProxyEngine On
    SSLCertificateFile    /etc/ssl/XXXXX_webserver_ssl.crt
    SSLCertificateKeyFile /etc/ssl/XXXXX_webserver_ssl.key
    
    RewriteCond %{HTTP_HOST} ^sub\.domainA\.com$ 
    RewriteRule ^(.*)$ https://subdomain.domainB.com/$1 [P,L]
    

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 2022-09-30
      • 2014-10-09
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      相关资源
      最近更新 更多