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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)