2

I have for example 2 domain names gl.example that points to /public_html/ (which has subfolder /public_html/tlf/) and tlf.example that points to the subfolder /public_html/tlf/

How do I redirect so that if users visit https://gl.example/tlf/example.php it goes to https://tlf.example/example.php

Basically I want it everything under gl.example/tlf to look like it's on nte tlf.example domain.

Which .htaccess should I edit? The one under public_html/ or the one under /public_html/tlf/? Would it like do an infinite loop since https://tlf.example points to the same /tlf folder?

3
  • 1
    Why do you want to solve this in .htaccess? It would normally be much better to create public_html/gl/ and public_html/tlf/ and set the document roots to those respective directories. It is never advisable to have domains in subdirectories of other domains. For an example of the problems it causes see Stop .htaccess automatically influencing subfolders Sep 2, 2019 at 23:02
  • To add to Stephen Ostermiller answer I also strongly advise to not use .htaccess when possible and put the configuration in the main configuration files. Doing so gives you: better security, more perfomances and specifically easier maintenance as it is far more clear which directives applies to which content. Sep 3, 2019 at 14:50
  • 1
    "much better to create public_html/gl/ and public_html/tlf/ and set the document roots to those respective directories." - Although if you are on shared hosting then that is probably not possible. However, you could leave /public_html/ as the document root for the main domain (gl.example) and possibly configure the secondary "addon" domain to point to (ie. set the document root for) a directory outside of the main domain's public HTML space. eg. /othersites/tlf/public_html/ - in order to keep the two domains entirely separate.
    – MrWhite
    Sep 3, 2019 at 16:32

1 Answer 1

2

or the one under /public_html/tlf/

In the /tlf/.htaccess file add the following mod_rewrite directives at the top to redirect any requests to the /tlf subdirectory via the main domain to the subdomain's root directory:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^gl\.example [NC]
RewriteRule (.*) https://tlf.example/$1 [R=301,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.