子域 URL 动态重定向。 .htaccess

Subdomain URL Redirect dynamically. .htaccess

我想使用 .htaccess 重定向 url 喜欢。

abc.website.com 到网站。com/folder/abc http://abc.website.com to http://www.website.com/folder/abc

使用 .htaccess 来自 PHP 服务器

使用以下规则,

RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www|webmail|help|whm|root)
RewriteCond %{HTTP_HOST} ^(.+?)\.website.com
RewriteRule ^ http://www.website.com/folder/%1 [R=301,L]

尝试将其放入您的 .htaccess 文件中:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.website.com
RewriteRule ^(.*)$ http://website.com/folder/abc/ [L,NC,QSA]

对于更通用的规则(适用于任何子域,而不仅仅是子域),将最后两行替换为:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.abc.website\.com
RewriteRule ^(.*)$ http://website.com/folder/%1/ [L,NC,QSA]

希望对你有用。