htaccess 子域

编程入门 行业动态 更新时间:2024-10-18 20:28:23
本文介绍了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 子域

本文发布于:2023-10-31 16:07:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!