htaccess redirect subdomain to domain

2019-09-23 03:56发布

there are a lot of posts related to this topic. but finding one exactly the same will take a lot of time. so Ill just simply ask agian if this has been asked before.

I would like to redirect a url like this "somename.mysite.com" to a url like "mysite.com/test/somename". notice the "somename" is a daynamic value, how can I write the rewrite_rule in htaccess?

in htaccess file there is already something:

<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 do I place the answer you give me.

Thank you for any help in advance.

2条回答
Root(大扎)
2楼-- · 2019-09-23 04:16
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mysite\.com [NC]
RewriteRule ^(.*) /test/%1/$1 [L]
查看更多
可以哭但决不认输i
3楼-- · 2019-09-23 04:42
<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>
查看更多
登录 后发表回答