Redirect subdomain to sub-folder

后端 未结 1 1128
星月不相逢
星月不相逢 2021-01-16 16:04

I need to write rewrite rule, to redirect subdomains to sub-folder.

Example: subdomain.domain.io should be redirected to domain

相关标签:
1条回答
  • 2021-01-16 16:21

    You can use this rule in your site root .htaccess:

    RewriteEngine On
    
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.io$ [NC]
    RewriteRule ^ apps/%1%{REQUEST_URI} [L]
    
    • RewriteCond %{ENV:REDIRECT_STATUS} ^$ is used to prevent looping of this rule.
    • %1 is back-reference of subdomain text captured in 2nd RewriteCond.
    0 讨论(0)
提交回复
热议问题