【问题标题】:mod_rewrite needed需要 mod_rewrite
【发布时间】:2010-12-07 20:17:49
【问题描述】:

可以说我有一个域 example.com,并且我打开了通配符 dns。在 example.com 上,用户可以使用用户名和密码进行注册。注册完成后,username.example.com 开始重定向到 example.com/script/script.php?user=username。地址栏仍会显示 username.example.com

.htaccess 文件的内容是什么?

我对 mod_rewrite 的专业知识为零。请指教。谢谢和问候。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite subdomain


    【解决方案1】:

    假设您的主机配置为提供来自同一个 DocumentRoot 的所有主机名,那么您会想要这样的东西:

    RewriteEngine On
    #If Not Match example.com and Not Match www.example.com
    RewriteCond %{HTTP_HOST} !^example\.com
    RewriteCond %{HTTP_HOST} !^www\.example\.com
    #then rewrite according to this rule
    RewriteRule ^(.*)$ script/script.php?user=%{HTTP_HOST}
    

    如果您在共享主机上并且无法指定调试日志文件,请在您有权访问的测试服务器上进行自己的测试。

    【讨论】:

    • 差不多,虽然我没有测试过,所以可能不完全正确。
    【解决方案2】:

    为此,您需要的不仅仅是 mod_rewrite - 您还需要阅读 apache virtual hosts

    【讨论】:

    • 不,你没有。 Apache 虚拟主机实际上只是另一种更简单的 URL 重写方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-31
    • 2010-12-31
    • 1970-01-01
    相关资源
    最近更新 更多