duanoucuo7045 2014-11-19 12:39
浏览 38
已采纳

m.example.com不会正确重定向

I am trying to make pretty urls for my mobile site. I have a working site for desktop, and will give the user option to enter the mobile version.

I have a php file called mobile.php in same dir as the index.php. the parameters of the sites will be the same. the parameters for the desktop version is working fine, but. If i enter m.example.com it will go to my desktop version, however if i enter m.example.com/something it will go to the mobile version.

    # changing www to nonwww
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#redirect for the mobile site
RewriteCond %{HTTP_HOST} ^m.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/?   [NC]
RewriteRule ^(.*)$ mobile.php?site=%1&brand=%2&model=%3&repid=%4 [L]



#redirect for dekstop.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/?   [NC]
RewriteRule .*    index.php?site=%1&brand=%2&model=%3&repid=%4  [L]

furthermore. When i am at the mobile site, i try to link to my resources src="/image.png". on the desktop it will work fine, but the mobilesite will make the url for the file m.example.com/image.png and can't find the resources. I bypassed by entering the whole URL, but would like to use the other way.

I hope some one can help me out on this ;)

  • 写回答

1条回答 默认 最新

  • douchongbang6011 2014-11-19 14:09
    关注

    Looks like culprit is your second rule that doesn't match landing page URI /, try this:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    #redirect for the mobile site
    RewriteCond %{HTTP_HOST} =m.example.com
    RewriteRule ^/?$ mobile.php [L]
    
    RewriteCond %{HTTP_HOST} =m.example.com
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/? mobile.php?site=$1&brand=$2&model=$3&repid=$4 [L,QSA]
    
    #redirect for dekstop.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/?  index.php?site=$1&brand=$2&model=$3&repid=$4 [L,QSA]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 asp.textbox后台赋值前端不能显示什么原因
  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误