2013-01-03 146 views
0

我想讓這個joomla網站重定向到一個名爲mobile.backuptoweb.co.uk的子域,當在移動設備上使用。但我也想保留現有的重寫規則,以確保所有用戶都被重定向到www。 url和trailing /被刪除。Joomla htaccess重定向到移動網站

目前它只是在移動設備上查看時重定向到無限循環。

的htaccess:

## 
# @package  Joomla 
# @copyright Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved. 
# @license  GNU General Public License version 2 or later; see LICENSE.txt 
## 


## Can be commented out if causes errors, see notes above. 
Options +FollowSymLinks 

## Mod_rewrite in use. 

RewriteEngine On 

## Begin - Rewrite rules to block out some common exploits. 
# If you experience problems on your site block out the operations listed below 
# This attempts to block the most common type of exploit `attempts` to Joomla! 
# 
# Block out any script trying to base64_encode data within the URL. 
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR] 
# Block out any script that includes a <script> tag in URL. 
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR] 
# Block out any script trying to set a PHP GLOBALS variable via URL. 
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 
# Block out any script trying to modify a _REQUEST variable via URL. 
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
# Return 403 Forbidden header and show the content of the root homepage 
RewriteRule .* index.php [F] 
# 
## End - Rewrite rules to block out some common exploits. 

## Begin - Custom redirects 
# 
# If you need to redirect some pages, or set a canonical non-www to 
# www redirect (or vice versa), place that code here. Ensure those 
# redirects use the correct RewriteRule syntax and the [R=301,L] flags. 

# mobile site redirection 
RewriteCond %{HTTP_REFERER} !^http://(.*).backuptoweb.co.uk/.*$ [NC] 

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera   mobile|palmos|webos|googlebot-mobile" [NC] 
RewriteRule ^(.*)$ http://mobile.backuptoweb.co.uk/$1 [L,R=302] 

RewriteCond %{HTTP_HOST} ^backuptoweb.co.uk [NC] 
RewriteRule ^(.*)$ http://www.backuptoweb.co.uk/$1 [L,R=301] 

# index.php to/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/ 
RewriteRule ^(.*)index\.php$ /$1 [R=301,L] 
# 
## End - Custom redirects 

## 
# Uncomment following line if your webserver's URL 
# is not directly related to physical file paths. 
# Update Your Joomla! Directory (just/for root). 
## 

RewriteBase/

## Begin - Joomla! core SEF Section. 
# 
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 
# 

## End - Joomla! core SEF Section. 

回答

0

難道是所有移動流量重定向到您的移動子域可行和有第二個.htaccess文件在你的身邊做手機測試和改寫?

要檢查,如果我正確地理解您的意見,

對於非移動訪問者

http://backuptoweb.co.uk/something重定向到http://www.backuptoweb.co.uk/something

對於移動遊客

http://backuptoweb.co.uk/something重定向到http://www.mobile.backuptoweb.co.uk/something

如果它們來自您的移動網站。如果是這樣的話,你想

http://backuptoweb.co.uk/something重定向到http://www.backuptoweb.co.uk/something


你覺得這對邏輯和秩序?

一些標誌可能需要工作至www.backuptoweb.co.uk/something。


看看這是如何爲你工作的。測試時一定要清除瀏覽器緩存。

如果有任何mod_rewrite的大師在那裏,我還需要改進

歡迎提出意見
Options +FollowSymLinks 
RewriteEngine On 

# Jooomla stuff here 

# rewrite index.php to/

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/ 
# RewriteRule ^(([^/]+/)*)index\.php$ http://www.backuptoweb.co.uk$1 [R=301] *** updated 
RewriteRule ^(([^/]+/)*)index\.php$ http://www.backuptoweb.co.uk/$1 [R=301] 


# check if coming from mobile site 
# if yes continue to main site 

# RewriteCond %{HTTP_REFERER} ^http://www\.mobile\.backuptoweb\.co\.uk/ [NC] *** updated 
RewriteCond %{HTTP_REFERER} ^http://mobile\.backuptoweb\.co\.uk/ [NC] 

RewriteRule (.*) http://www.backuptoweb.co.uk$1 [R=301,L] 


# send any remaining mobile visitors to mobile site 

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] 
RewriteCond %{http_host} !^$ 
# RewriteRule (.*) http://www.mobile.backuptoweb.co.uk/$1 [R=301,L] *** updated 
RewriteRule (.*) http://mobile.backuptoweb.co.uk/$1 [R=301,L] 


# rewrite non-www to www 

RewriteCond %{http_host} ^backuptoweb\.co\.uk$ 
RewriteCond %{http_host} !^$ 
RewriteRule (.*) http://www.backuptoweb.co.cuk/$1 [R=301,L] 
+0

可能,爲什麼什麼,我問可行不? – user794846

+0

我很笨,我忘了從重定向中刪除L,不知道它是否仍然非常正確。 – user794846

+0

你想做什麼可能是可行的。我很難看到你想要考慮的所有重寫組合,所以我試圖簡化場景,讓所有的工作都能正常工作,然後從那裏開始工作。祝你好運! –