0

I installed an SSL Certificate on my server, and https works fine.

Http redirect works fine for example http://login.example.com -> https://example1.com/index.html

But redirect from https not working, for example https://login.example.com -> https://example1.com/index.html.

its just go to the main page of my server https://redirect.example.com

Any suggestions on how to get the redirect from https to work?

Thanks !

<VirtualHost *:80> RewriteEngine On ServerName redirect.example.com RewriteCond %{HTTP_HOST} ^login\.example\.com(.*) RewriteRule (.*) https://example1.com/index.html [L] </VirtualHost> <VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/httpd/my.crt SSLCertificateKeyFile /etc/httpd/my.pem ServerName redirect.mydomain.com RewriteEngine On ServerName redirect.example.com RewriteCond %{HTTP_HOST} ^login\.example\.com(.*) RewriteRule (.*) https://example1.com/index.html [L] </VirtualHost> 

Thanks!

1
  • i will appreciate any help! Commented Sep 26, 2016 at 12:28

3 Answers 3

1

I see that you have a duplicate ServerName directive in your SSL host declaration. That could be causing trouble.

From the Apache documentation:

If you are using name-based virtual hosts, the ServerName inside a section specifies what hostname must appear in the request's Host: header to match this virtual host.

Sign up to request clarification or add additional context in comments.

7 Comments

thanks, I tried to remove the servername on https but it doesnt work
If you're expecting visitors to come from login.example.com, then this is what you should use as ServerName instead of redirect.mydomain.com. Then restart Apache
what do you mean with use as ServerName instead of redirect.mydomain.com?
the server name is like http ServerName redirect.example.com and its works, im not sure what do you mean with your answer, what should I do different?
Assuming your URL is https://login.example.com, you just put this line in your SSL host declaration: ServerName login.example.com. It should match the actual domain name.
|
0

Use server alias for your Rewrite Rule:

ServerAlias login.example.com 

you can use multiple ServerAlias for multiple Rewrite Rule

Comments

0

What exactly do you mean by multiple rules ? Multiple domain names/subdomains ?

A plain redirect of http(s)://login.example.com to https://example1.com/index.html should be achieved this way:

<VirtualHost *:80> ServerName login.example.com RewriteEngine On RewriteCond %{HTTP_HOST} ^login\.example\.com RewriteRule (.*) https://example1.com/index.html [L] </VirtualHost> <VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/httpd/my.crt SSLCertificateKeyFile /etc/httpd/my.pem ServerName login.example.com RewriteEngine On RewriteCond %{HTTP_HOST} ^login\.example\.com RewriteRule (.*) https://example1.com/index.html [L] </VirtualHost> 

Important: ServerName should match your SSL certificate's Common Name (unless it's a wildcard certificate).

NB: RewriteEngine may be overkill for your purpose since the Apache mod_alias module provides the Redirect directive which may be sufficient here. From the Apache documentation: When not to use mod_rewrite

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.