【问题标题】:Route subdomain to a directory in server将子域路由到服务器中的目录
【发布时间】:2013-06-05 20:12:43
【问题描述】:

如何在 localhost 中创建子域。在使用 windows 机器时,我尝试编辑 windows host 文件

  127.0.0.1               localhost
  127.0.0.1/subdomain     subdomain.localhost

获得类似的东西。

http://subdomain.localhost


更新: 首先,这个问题是在没有任何背景的情况下提出的,这次更新是为了提高质量。

通过编辑 vhosts 文件可以实现以下功能。

虚拟主机:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.com
    DocumentRoot "C:/wamp/www/subdomain/"
    ServerName localhost
    ServerAlias subdomain.localhost
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
</VirtualHost>

现在在编辑主机时,可以解决以下问题。

主机

127.0.0.0              subdomain.localhost

现在我找到了一个更好的例子,使用RewriteRule (适用于任何子域,而不仅仅是本地主机)

在 .htaccess 文件中:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.example.com
RewriteRule ^(.*)$ http://example.com/subdomains/sub/$1 [L,NC,QSA]

对于更一般的规则,我们可以替换最后两行:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/subdomains/%1/$1 [L,NC,QSA]

我不是 mod_rewrite 专家,请帮助改进和指导。
谢谢。

【问题讨论】:

    标签: apache


    【解决方案1】:

    我认为这已经解决了。 This 可能会回答你的问题:

    【讨论】:

    • 没问题...如果对您有用,请务必检查答案是否已接受! - 谢谢!
    • 问题是我在 localhost 中有文件,我想添加一个子域,
    • 愚蠢的问题,但是您是否尝试为您的子域添加子目录?
    • 您的链接指向与我回答的类似示例,它只是一个不同的帮助站点!
    猜你喜欢
    • 1970-01-01
    • 2017-10-09
    • 2014-08-03
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 2018-05-20
    相关资源
    最近更新 更多