简体   繁体   English

HTTPS重定向到特定的URL

[英]HTTPS redirect to specific URL

I have the below redirect set in httpd.conf which redirects subdomain.domain.com to domain.com/topics/apps 我在httpd.conf中设置了以下重定向,该重定向将subdomain.domain.com重定向到domain.com/topics/apps

RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [OR]<br>
RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com.gov$<br>
RewriteRule ^/(.*)$ http://www.domain.com/topics/apps[R=301]

But if i try the same with https, it wont redirect to that page but shows domain.com homepage (not redirect). 但是,如果我尝试使用https进行相同操作,它将不会重定向到该页面,而是显示domain.com主页(不重定向)。 I guess this is because the DNS entry for subdomain.domain.com is also having the same IP as domain.com. 我猜这是因为subdomain.domain.com的DNS条目也具有与domain.com相同的IP。

Can you guys suggest fixing this https redirect to http://domain.com/topics/apps . 你们可以建议修复此https重定向到http://domain.com/topics/apps

Thanks, Sudeer. 谢谢,苏德

My experience is that Apache, by default, handles SSL with a separate VirtualHost on a different port. 我的经验是,默认情况下,Apache使用不同端口上的单独VirtualHost处理SSL。 Look for the VirtualHost which is listening on 443 and set the redirection there. 查找正在侦听443VirtualHost ,然后在其中设置重定向。

Do you have access to the Vhosts ? 您可以访问虚拟主机吗? If so, I would skip the rewrites and simply do this(and restart httpd): 如果是这样,我将跳过重写并简单地执行此操作(然后重新启动httpd):

<VirtualHost *:443>
  ServerName subdomain.domain.com
  ServerAdmin you@you.com
  DocumentRoot this/needs/to/exist
  Redirect permanent / http://domain.com/topics/apps
</VirtualHost>

You need to set up a Virtual Host on Port 443 and also set it to Named Virtual Hosts when the IP is the same but the names are different. 您需要在端口443上设置虚拟主机,并在IP相同但名称不同时将其设置为“命名虚拟主机”。

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName myserver.de
    RewriteEngine On
    RewriteLog /var/log/httpd/rewrite.log
    RewriteLogLevel 0  

    RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com.gov$
    RewriteRule ^/(.*)$ http://www.domain.com/topics/apps[R=301]
</VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM