【问题标题】:htaccess rewrite all subdomain to index.phphtaccess 将所有子域重写为 index.php
【发布时间】:2013-05-19 16:02:00
【问题描述】:

我知道这个问题被问了很多,但我不知道为什么它对我不起作用 :-? 这是我的 htaccess:

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
#  Rules
RewriteRule ^(.*)$ index.php

此代码应该重写任何路径的任何链接,包括 index.php 的任何子域,但它没有。

域名也不应该进入htaccess,因为它是未知的!!! 我从 127.0.0.1 调用这个 htaccess,许多网站应该链接到 localhost:

/etc/hosts

127.0.0.1   localhost
127.0.1.1   mypc
127.0.0.1   google.com
127.0.0.1   example.com

在这里,我的浏览器确实可以成功浏览 google.com 或 example.com,但找不到它们的子域,例如 sub1.google.com 或 sub1.example.com。

index.php

<?php
$uri = 'http'. ($_SERVER['HTTPS'] ? 's' : null) .'://'. $_SERVER['HTTP_HOST'].$_SERVER[REQUEST_URI];
print_r($uri);
?>

有人知道这个 .htaccess 代码是如何对子域起作用的吗?

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting webserver localhost


    【解决方案1】:

    如果我理解你的问题,你问为什么google.com 正确加载本地主机上的 index.php 但sub1.google.com 等子域没有。

    您不能使用 hosts 文件覆盖子域 DNS。为此,您需要将所有子域添加到 hosts 文件中,或者设置一个私有 DNS 服务器,其中 google.com*.google.com 的记录指向 127.0.0.1。

    【讨论】:

    • 你是真的。我终于通过使用 dnsmasq 和编辑 /etc/dnsmasq.conf 做到了,它成功了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多