【问题标题】:Rewrite domain name/url with htaccess用 htaccess 重写域名/url
【发布时间】:2015-10-17 14:49:11
【问题描述】:

我需要重写以下网址:

mydomain.com/dashboard/index.php?user=john-dow

john-dow.mydomain.com/dashboard/index.php

所以我想获取查询字符串值并将其放在我的域的开头,后跟一个点。目标是创建一个自定义的用户 url,因此它看起来对用户非常友好。但实际上,我不知道我该怎么做。 .htaccess 可以吗?如果是,怎么做?

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    在你的dashboard/.htaccess中使用:

    RewriteEngine on 
    RewriteCond %{HTTP_HOST} !^(.+)\.mydomain\.com$ [NC]
    RewriteCond %{QUERY_STRING} ^user=(.+)$
    RewriteRule ^index\.php$ http://%1.mydomain.com/dashboard/index.php? [R,L]
    

    【讨论】:

    • 嗨,我试过了。它根据我的需要创建 url,例如:john-dow.mydomain.com/dashboard/index.php 但它没有得到 index.php 文件,它显示找不到服务器。
    • .htaccess 没有问题。您需要配置服务器和 DNS 以使用通配符 DNS 记录。
    • 嗨,你能推荐我或分享一下吗?如何配置服务器和DNS?另一件事,我可以在我的 ubuntu 操作系统上的 localhost 上测试它吗?谢谢
    • 非常感谢。你能建议我一个链接,那里有完整的通配符设置教程。再次感谢。
    • 尝试使用 Google 的“通配符 DNS”,以及您的 DNS 服务器名称或网络托管。
    猜你喜欢
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2014-05-15
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多