0

I want to redirect https://aaa.subdomain.example.com/path to https://subdomain.example.com/aaa/path
But how to do that with apache .htaccess file? I tried this, however, it didn't work :(

RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.subdomain\.example\.com [NC]
RewriteRule .* https://subdomain.example.com/%1/${REQUEST_URI}
Dounick
  • 3
  • 2

1 Answers1

0

Important: the following instructions are for information purposes only. You may need to change the code so that it works in your situation.

Using your FTP software or our FTP Manager, add and adapt the following code in the .htaccess file located in the root of your Website:

RewriteCond %{HTTP_HOST} ^(.*).domain.com [NC]
RewriteCond %{DOCUMENT_ROOT}/%1/ -d
RewriteCond %1::%{REQUEST_URI} !^(.*?)::/1/?
RewriteRule "^(.*)$" "%{DOCUMENT_ROOT}/%1/$1" [L]

Explanations for the third line: [https://stackoverflow.com/a/15981056][1]

In the first line replace:

domain with your domain name com with your domain name extension (ch, fr, etc.)

PJiwon
  • 50
  • 5
  • Thank you, but it didn't work either. The browser just kept returning a 404 error, it seemed that it didn't rewrite the URL at all. – Dounick Apr 30 '22 at 05:41
  • @Dounick did you enable mod_rewrite? – mashuptwice Apr 30 '22 at 05:45
  • Ah! That's a really silly mistake!!! But here comes a new problem, it always returns a 403 code, and I don't know what's going wrong. – Dounick Apr 30 '22 at 06:06
  • Oh, it's OK now, I solved it by changing %{DOCUMENT_ROOT} to the domain that I want to redirect to, thank you! – Dounick Apr 30 '22 at 06:10