【问题标题】:Miltiple domain/subdomain using htaccess使用 htaccess 的多个域/子域
【发布时间】:2016-01-21 12:00:18
【问题描述】:

我的网站有文档根 ~/public_html 我正在尝试使用 htaccess 组织多域/子域重定向。

可能的重定向逻辑:如果找到域/子域目录 - 执行重定向,否则抛出 404 错误。

可能的目录结构:

public_html/
            .htaccess (main redirect router)
public_html/
            domain-1/
                    application/
                    public_html/
                                .htaccess
public_html/
            domain-2/
                    application/
                    public_html/
                                .htaccess
public_html/
            domain-3/
                    application/
                    public_html/
                                .htaccess
public_html/
            subdomain-1.domain-1/
                                application/
                                public_html/
                                            .htaccess
public_html/
            subdomain-2.domain-1/
                                application/
                                public_html/
                                            .htaccess

非常感谢您的帮助。 谢谢。

【问题讨论】:

  • 这就是 VirtualHosts 的优势所在。 httpd.apache.org/docs/2.2/en/vhosts
  • 很遗憾,根据我的主机限制,我无法访问 apache 设置。
  • 仅使用 htaccess 可以解决我的问题吗?
  • 取决于您的主机。您是否有权使用可以将新域添加到托管包的工具?
  • apache 必须以某种方式将您的域映射到您的网络空间。这只是在虚拟主机 afaik 中。

标签: php .htaccess mod-rewrite redirect


【解决方案1】:

你的 .htaccess 文件应该有

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain.domain.in [NC]
RewriteRule ^(.*)$ http://www.hardikvyas.in/$1 [L,R=301]

RedirectMatch ^/$ /redirection directory name/

试试这个。

【讨论】:

猜你喜欢
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-26
  • 2016-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多