Redirect http to https and then redirect it to subdomain's folder?

468 Views Asked by At

First case:

I tried to redirect http to https and following rule works well.

For example: http://subdomain.domain.com to https://subdomain.domain.com.

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

Second Case: I tried to redirect http://subdomain.domain.com to http://subdomain.domain/folder. For this I used this rule:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com  
RewriteRule ^(.*)$ /folder/$1

I want these redirection:

http://subdomain.domain.com to https://subdomain.domain.com/folder

and

https://subdomain.domain.com to https://subdomain.domain.com/folder

I tried merging the above rules but no luck.

One more thing, I am not using .htaccess ,instead I put these rules to /etc/apache2/sites-available/default.

1

There are 1 best solutions below

0
On BEST ANSWER

Answering my own question.

Actually there are two files in /etc/apache2/sites-available/

  1. default
  2. default-ssl

I put the rule to redirect http to https as

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

in default file and

put rule to redirect to sub-domain's folder as

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com  
RewriteRule ^(.*)$ /folder/$1

in default-ssl file.