【问题标题】:Simple subdomain redirect PHP简单的子域重定向 PHP
【发布时间】:2013-10-21 07:59:04
【问题描述】:

我的移动应用程序有一个子域,例如 http://m.traffic.domain.com 现在我希望我的用户可以通过访问http://m.traffic.domain.com/username 访问他们的页面 这将在内部指向http://m.traffic.domain.com/index.php?username=$1 为此,我有以下 .htaccess 重写代码,但它没有按预期工作,而是将所有页面重定向到 http://m.traffic.domain.com/index.php?username=$1 这个 页面

# 默认使用 PHP5 Single php.ini AddHandler 应用程序/x-httpd-php5s .php AddHandler 应用程序/x-httpd-php .aspx 重写引擎开启 RewriteCond %{HTTP_HOST} ^m\.traffic\.domain\.com$ [NC] RewriteCond %1 !^www$ [NC] RewriteRule ^(.+)$ mobile/index.php?username=%1 [L] 命令允许,拒绝 允许所有人 文件>

子域http://m.traffic.domain.com指向一个名为mobile的目录,可以访问http://traffic.domain.com/mobile

【问题讨论】:

    标签: php .htaccess subdomain


    【解决方案1】:

    试试这个代码:

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php
    AddHandler application/x-httpd-php .aspx
    
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^m\.traffic\.domain\.com$  [NC]
    RewriteRule ^([^.]+)/?$ /index.php?username=$1 [L,QSA]
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    

    来自RewriteRule 的匹配组是$1, $2 而不是%1, %2,您不需要/mobile,因为您的请求是针对m.traffic.domain.com 而不是traffic.domain.com

    【讨论】:

    • 感谢它通过一点编辑 RewriteRule ^([^.]+)/?$ /index.php?username=$1 [L,QSA]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 2014-12-17
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多