Search code examples
.htaccesshttp-redirectsubdirectory

.htacces redirect from domain 1 to domain 2 subdir, keeping path


I have found plenty of useful answers in this forum that got me to the point I'm at, however the configuration of my .htaccess redirect is still not 100% perfect.

Set-up

I have two domains registered:

  • domain1.is (only domain)
  • domain2.me (domain + hosting)

The domain1 redirects as wildcard everything to domain2.

What I'm trying to do

I have installed yourls (url shortened) on domain2.me/yourls and want to redirect all domain1.is/randomstring to domain2.me/yourls/randomstring.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.is$
RewriteRule (.*) https://domain2.me/yourls/$1 [R=301,L]
RewriteRule ^$ store [L,R=301]

The issue

So far I got that domain1.is/randomstring goes to domain2.me/randomstring, however the subdirectory in the .htacess file seems to be completely ignored, effectively rendering the whole system unusable.

I've tried adding a condition, changing the subdirectory, etc. but can't seem to find the reason why. Can anyone help please?

Thanks in advance and cheers from Berlin!


Solution

  • I'll share my solution in case someone else stumbles upon this conversation. The details/history are in the comments of the question.

    TLDR;

    Just set up a wildcard redirect to the subdirectory. DNS records

    (not sure if the first redirect is useful, but still). Important point: you don't even need to touch the .htaccess file (in my particular case yourls already had one, so I left it as it is).

    Credit: thanks @CBroe for pointing me in the right direction.