Lelio Faieta Lelio Faieta - 3 months ago 39
Apache Configuration Question

htaccess redirect folder to a third level domain

I have a website

https://www.mywebsite.it
with a few pages in the root.

Then I have a folder named
myapp
where I have an application developed.
Actually the application myapp can be accessed via:

https://www.mywebsite.it/myapp
https://myapp.mywebsite.it


What I want to do is: if the user navigates to https://www.mywebsite.it/myapp apache will redirect him to https://myapp.mywebsite.it

Is something like:

RewriteEngine On
RewriteRule ^/?myapp/ https://myapp.mywebsite.it/? [R=301,L]


inside the vhost configuration file going to work?

Answer

Inside myapp/.htaccess you can use this rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?(mydomain\.it)$ [NC]
RewriteRule .* http://myapp.%1/$0 [L,R=301,NE]