多级子域htaccess重定向

时间:2016-04-27 01:21:51

标签: php apache .htaccess redirect mod-rewrite

我正在尝试使用htaccess进行多级子域重定向。即http://jon.doe.example.com/?number=120384重定向到http://www.example.com/lookup.php?firstname=joe&lastname=doe&number=120384

这是我尝试过的,但它不起作用。

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteCond %{HTTP_HOST} ^([^.]+).example.com
RewriteRule ^/?$ /lookup.php?firstname=%1&lastname=%2&%{QUERY_STRING} [P,L,QSA]

当我致电http://jon.doe.example.com/?number=120384时,它只会重定向到www.example.com

1 个答案:

答案 0 :(得分:2)

您应该修改.htaccess中的代码,如下所示:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.example\.com$
RewriteRule ^/\?number=(.*)$ /lookup.php?firstname=%1&lastname=%2&number=$1 [P,L,QSA]

此处,第二级子域名将在参数%1中提取,%2let navigationBarItems = self.subviews var lableInserted = false var buttons:[UIView] = [] for navigationBarItem in navigationBarItems{ print(String(navigationBarItem.dynamicType)) if String(navigationBarItem.dynamicType) == "_UINavigationBarBackground"{ if syncBarDataSource != nil{ navigationBarItem.frame.origin.y = bounds.origin.y + CGFloat(syncBarDataSource!.barHeight) - CGFloat(maxHeight/2) navigationBarItem.frame.size.height = bounds.size.height + CGFloat(maxHeight) } else { navigationBarItem.frame.origin.y = bounds.origin.y - CGFloat(maxHeight/2) navigationBarItem.frame.size.height = bounds.size.height + CGFloat(maxHeight) } } if String(navigationBarItem.dynamicType) == "UINavigationButton" || String(navigationBarItem.dynamicType) == "UINavigationItemButtonView"{ buttons.append(navigationBarItem) } if let lable = navigationBarItem as? UILabel{ lableInserted = true lable.text = syncBarDataSource.text if syncBarDataSource!.barHeight > 0{ lable.hidden = false } else { lable.hidden = true } } } 中的第一级子域。查询字符串参数编号的值将以$ 1的形式提供。