简体   繁体   English

使用.htaccess将流量重定向到同一域

[英]Using .htaccess to redirect traffic to same domain

Well it's kind of hard typing a title to describe what I want to do. 好吧,很难输入标题来描述我想要做什么。

Basically I have a website that I've been asked to develop a mobile site for. 基本上,我有一个网站被要求为其开发移动网站。 This website has various domains (such as .co.za , .com , .za.net ) but they all run from the same folder on the server (so I only have one .htaccess file). 该网站具有多个域(例如.co.za.com.za.net ),但是它们都在服务器上的同一文件夹中运行(因此我只有一个.htaccess文件)。

I want to be able to redirect the traffic that goes to www.example.co.za to m.example.co.za and traffic that goes to www.example.com to m.example.com . 我希望能够重定向转到交通www.example.co.zam.example.co.za和去交通www.example.comm.example.com

How would I need to modify this .htaccess file to achieve that. 我需要如何修改此.htaccess文件才能实现这一目标。

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteRule ^$ http://m.example.com/ [L,R=302]

How about: 怎么样:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ http://m.%2/ [L,R=302]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM