将文件夹重定向到同名的子域

时间:2017-05-26 15:30:53

标签: php .htaccess redirect url-rewriting

我用来让用户访问domain.com/dashboard,但现在希望他们转到dashboard.domain.com。一些用户仍在使用旧地址并获得一个非工作/非常丑陋的页面。是否可以将子文件夹(domain.com/dashboard)重定向到子域(dashboard.domain.com),即使文件夹名称本身是仪表板(public_html / dashboard),或者只是更容易更改子文件夹名称与不同的东西?这是我目前在public_html的.htaccess文件中所拥有的内容。

RewriteCond %{HTTP_HOST} ^dashboard.domain.com$
RewriteCond %{REQUEST_URI} !^/dashboard/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ /dashboard/$1
RewriteCond %{HTTP_HOST} ^dashboard.domain.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(/)?$ dashboard/index.php [L]

1 个答案:

答案 0 :(得分:0)

创建dashboard/.htaccess如果它不存在并将此规则作为第一条规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^dashboard\.domain\.com$ [NC]
RewriteRule .* http://dashboard.domain.com/$0 [L,NE,R=301]