【问题标题】:Joomla htaccess mobile redirectJoomla htaccess 移动重定向
【发布时间】:2025-12-03 23:30:02
【问题描述】:

我有 2 个版本的网站,桌面版和移动版:

  1. www.olivashot.com
  2. www.mobile.olivashot.com

我的 htacces 正在将移动设备重定向到移动版本。

问题...

1- 如果访问者来自 google,因为他搜索了“thing”,完整链接显示为“www.olivashot.com/index.php/thing”,它会重定向到“www.mobile.olivashot.com/index.php/thing” (我有一个快乐的访客)

2- 但是如果 google 中的链接是:“www.olivashot.com/thing” >>> 他会被重定向到“www.mobile.olivashot.com” (我正在失去一位访客,因为我没有表现出他的预期)

我认为这是因为我正在重写“某事”以退出 joomla 网站中的默认“index.php”

RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script

RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.




RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://www.mobile.olivashot.com/$1/ [R=301,L]

【问题讨论】:

    标签: .htaccess redirect mobile joomla


    【解决方案1】:

    您应该将最后一个块放在 之前有一些退出点的 Joomla 自定义重定向。这意味着顺序应该是:

    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
    RewriteRule ^(.*)$ http://www.mobile.olivashot.com/$1/ [R=301,L]
    
    
    ## Begin - Joomla! core SEF Section.
    ...
    

    您可以删除文件顶部已启用的 RewriteEngine On 行。 为了增加安全性,一旦您开始工作,您可以查看样板模板的 .htaccess 文件 h5bp.com

    【讨论】:

      最近更新 更多