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 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: