本文介绍了htaccess 子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 htacess:
Howto make this with htacess:
subdomain.domain -> domain/subdomain (no redirect on client side) domain/subdomain -> subdomain.domain (redirect)我首先重定向:
RewriteRule ^subdomain/ - [L] RewriteCond %{HTTP_HOST} ^subdomain.domain [NC] RewriteRule (.*) subdomain/$1 [L]htacess的形式是怎么插入的:
How is it inserted in the form htacess:
AddDefaultCharset utf-8 DirectoryIndex index.php index.html index.htm Options All -Indexes ErrorDocument 404 /404.html ErrorDocument 403 /404.html RewriteEngine On RewriteCond %{HTTP_HOST} ^domain RewriteRule (.*) www.domain/$1 [R=301,L] RewriteCond %{REQUEST_URI} !.(png|jpg|jpeg|gif)$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*)$ index.php/$1 [QSA] 推荐答案这是一个基于通配符的解决方案,因此它适用于任意数量的子域.
This is a wildcard based solution, so it sould work for any number of subdomains.
这会将 domain/foo/bar 重定向到 foo.domain/bar:
This will redirect domain/foo/bar to foo.domain/bar:
RewriteCond %{HTTP_HOST} ^domain$ [NC] RewriteRule ([^/]+)(/.*|$) $1.domain/$2 [R=302]这将处理(内部重写)虚拟主机:
This will handle (internal rewrite) the virtual hosts:
RewriteCond %{HTTP_HOST} ^(.*).domain$ [NC] RewriteRule (.*) %1/$1 [L]您可以考虑使用 301(永久重定向)而不是 302.
You might consider using 301 (permanent redirect) instead of the 302.
我强烈建议您为您的主站点 domain 或 www.domain 设置一个 VirtualHost 和一个单独的用于处理虚拟子域.
I strongly suggest you have a VirtualHost for your main site domain or www.domain and a separate one for handling the virtual subdomains.
仅针对某个子域:
RewriteCond %{HTTP_HOST} ^domain$ [NC] RewriteRule (subdomain)(/.*|$) $1.domain/$2 [R=302,L] RewriteCond %{HTTP_HOST} ^(subdomain).domain$ [NC] RewriteRule (.*) %1/$1 [L]更多推荐
htaccess 子域
发布评论