Htaccess redirect subdomain to domain

There are many posts related to this topic. but finding the exact same thing will take a long time. so I’ll just ask the hagian if it was asked before.

I would like to redirect a URL such as "somename.mysite.com" to a URL like "mysite.com/test/somename". note that "somename" is a day value, how can I write rewrite_rule in htaccess?

There is already something in the htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Where can I post the answer you give me.

Thanks for any help in advance.

-2
source share
2 answers
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_HOST} ^(\w+)\.mysite\.com [NC]
    RewriteRule .* http://mysite.com/test/%1 [R,L]

    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
+1
source
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mysite\.com [NC]
RewriteRule ^(.*) /test/%1/$1 [L]
0
source

Source: https://habr.com/ru/post/1786010/


All Articles