【问题标题】:Rewrite subdomain url like bigcommerce.com重写子域网址,如 bigcommerce.com
【发布时间】:2014-09-10 07:15:48
【问题描述】:

我有 2 个文件夹 ab

我想将 url 重写为子域样式。

domain.com/a => a.domain.com => 它将运行文件夹 a

domain.com/b => b.domain.com => 它将运行文件夹 b

提前致谢

【问题讨论】:

    标签: mod-rewrite subdomain


    【解决方案1】:

    假设文件夹 ab 位于您域的根目录中,请尝试将其添加到您的 Web 文档根文件夹中的 .htaccess 文件中(通常是 public_htmlhtdocs):

    Options -Multiviews
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^([ab])\.domain\.com [NC]
    RewriteRule ^ %1%{REQUEST_URI} [L]
    

    这假定 mod_rewrite 已同时安装.htaccess 文件激活。 如果您不确定,要检查是否安装了 mod_rewrite,请查看phpinfo(); 输出中的已安装模块列表 默认情况下,不为 .htaccess 文件启用 mod_rewrite。如果您正在管理自己的服务器,请打开 httpd.conf 并确保 webroot 目录块包含以下行之一:AllowOverride FileInfoAllowOverride All

    【讨论】:

    • 感谢您的评论,但它不起作用,它会导致 500 内部服务器错误
    • 你确定安装了 mod-rewrite 吗? (请参阅答案中的说明。)
    • 我确定,我发现了你的错误,最后一行的 ^ 和 % 之间有一个空格。我删除了它。它运行但不正确,当我键入 a.domain.com 时,它没有运行到文件夹 a 或 b 中。它在根目录下运行 index.php
    • there was a space between ^ and % 不,那个空格是正确的。
    • 它造成 500 内部服务器错误。我不知道为什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2012-07-02
    • 1970-01-01
    • 2010-10-08
    • 2018-07-31
    相关资源
    最近更新 更多