0

我试图让这个 joomla 网站在移动设备上使用时重定向到一个名为 mobile.backuptoweb.co.uk 的子域。但我也想保留现有的重写规则,确保所有用户都被重定向到 www。url 和尾随 / 被删除。

目前它只是在移动设备上查看时重定向到无限循环。

访问:

##
# @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.
4

1 回答 1

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


你怎么看这个逻辑和顺序?

  • 将 index.php 重写为 / (绝对不要使用 [L] 标志)

  • 检查移动访问者是否来自移动站点。如果是,请使用 [L] 重写并发送到http://www.backuptoweb.co.uk/something

  • 检查移动访问者(而不是来自移动站点。如果是,请使用 [L] 重写并发送到http://www.backuptoweb.co.uk/something

  • 用 [R=301,L] 将 no-www 改写为 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]
于 2013-01-04T04:39:43.510 回答