简单的子域名重定向PHP [英] Simple subdomain redirect PHP
问题描述
我有一个子域我的移动应用程序是一样的 http://m.traffic.domain.com 现在我想,我的用户可以通过访问 http://m.traffic.domain.com/username访问他们的页面 这将在内部指向 http://m.traffic.domain.com/index.php ?用户名= $ 1 为了这个,我有如下的.htaccess重写code,但其工作不正常,而其重定向所有网页的 http://m.traffic.domain.com/index.php?username= $ 1本 页
I have a sub-domain for my mobile app which is like http://m.traffic.domain.com now I want that my users can access their page by visiting http://m.traffic.domain.com/username which will internally point to http://m.traffic.domain.com/index.php?username=$1 for this I have following .htaccess rewrite code but its not working as expected rather its redirecting all pages to http://m.traffic.domain.com/index.php?username=$1 this page
# 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]
RewriteCond %1 !^www$ [NC]
RewriteRule ^(.+)$ mobile/index.php?username=%1 [L]
<Files 403.shtml>
order allow,deny
allow from all
</Files>
子站点 http://m.traffic.domain.com 指向一个目录中称为移动这可以访问 http://traffic.domain.com/mobile
The subdomain http://m.traffic.domain.com points to a directory called mobile which can be accessed http://traffic.domain.com/mobile
推荐答案
试试这个code来代替:
Try this code instead:
# 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>
匹配组从重写规则
是 $ 1,$ 2
而不是%1%2
键,你不需要 /移动
,因为你的要求是 m.traffic.domain.com
不是 traffic.domain.com
Matched groups from RewriteRule
are $1, $2
instead of %1, %2
and you don't need /mobile
since your request is for m.traffic.domain.com
not traffic.domain.com
这篇关于简单的子域名重定向PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!