【问题标题】:.htaccess subdomain url rewrite.htaccess 子域 url 重写
【发布时间】:2013-10-29 13:14:12
【问题描述】:

我想重写一个 url,但总是没有得到足够的结果。

我想要网址 http://something.domain.com/index.php?arguments... 实际访问 http://domain.com/index.php?username=something&arguments...

我尝试过创建通配符条目 *.domain.com 并在互联网上使用一些代码,但没有任何效果。

我不断收到“默认网站页面” 任何想法如何解决这个问题?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    您可以在something 域的DOCUMENT_ROOT/.htaccess 文件中使用此代码:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^([^.]+)\.(domain\.com)$ [NC]
    RewriteRule ^(index\.php)$ http://%2/$1?username=%1 [L,QSA,NC,R]
    

    【讨论】:

    • 感谢您的回答。 “某事”实际上是用户名。所以,martin.domain.com 应该等价于 domain.com/index.php?username=martin
    • 它仍然显示“默认网页”消息。我应该删除 dns 条目“*.domain.com”吗?
    • 您在浏览器中看到的网址是什么?
    • 这是示例网址:martin.paneluser.com 我希望它实际访问 paneluser.com?index.php?username=martin
    • 是的,根据这条规则,它应该显示http://paneluser.com?index.php?username=martin 浏览器中的 URL 根本没有变化?
    【解决方案2】:

    感谢您的帮助! 看来我不用添加通配符dns条目,而是在cpanel中创建通配符子域。

    【讨论】:

      猜你喜欢
      • 2011-05-25
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 2019-04-25
      相关资源
      最近更新 更多