0

I'm trying to redirect example.com/x/y/.. to https://sub.example.com/x/y/.. with following rules in my htaccess-file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ https://sub.example.com/$1 [L,R=301]

The redirect however does not add the sub-path of the original URL to the new one. So instead of redirecting to https://sub.example.com/x/y/.., I'm just redirected to https://sub.example.com

Any suggestions why?

Sully
  • 169
  • 3
  • 13

1 Answers1

0

In the present scenario that you have described, Apache is not able to pass on the remaining part of the URI. You need to use %{HTTP_HOST}%{REQUEST_URI} in the line for RewriteRule. Please refer this example: Force SSL/https using .htaccess and mod_rewrite

Panda
  • 6,955
  • 6
  • 40
  • 55
Hiren
  • 130
  • 1
  • 2
  • 11
  • I changed the RewriteRule to `RewriteRule ^ https://sub.example.com/%{REQUEST_URI} [L,R=301]` but this does not work either. Then i tried to redirect first to https and then redirect to the location, but it just rewrites the hostname and forgets the rest. – Sully Sep 14 '16 at 15:23
  • O.k..did you try changing the `RewriteCond` line as well (as mentioned in the example)? – Hiren Sep 14 '16 at 15:32