简体   繁体   English

htaccess重定向后,从移动网站访问父网站的文件夹

[英]Access folder of parent website from mobile website after htaccess redirect

I'm redirecting my website to mobile website when access through a mobile device. 我通过移动设备访问时将我的网站重定向到移动网站。

Here's the htaccess code: 这是htaccess代码:

RewriteCond %{QUERY_STRING} !^desktop
RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|iphone [NC]
RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]

Folder structure of FTP is like this: FTP的文件夹结构如下:

Images
ProImages
Mobile // All mobile site data into this

When I attempt to access http://www.example.com/ProImages/abc.jpg from my mobile website, it doesn't show up because as soon as it tries to call www , it redirects to m . 当我尝试从我的移动网站访问http://www.example.com/ProImages/abc.jpg ,它没有显示,因为一旦它尝试调用www ,它就会重定向到m

I tried using ../ProImages but that again didn't solve the issue. 我尝试使用../ProImages但这又没有解决问题。

Anybody can help in this? 有人可以帮忙吗?

You can allow access to the image folder for the mobile version 您可以允许访问移动版本的图像文件夹

RewriteCond %{QUERY_STRING} !^desktop
RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|iphone [NC]
RewriteCond %{REQUEST_URI} !^/ProImages/ [NC]
RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]

You could do a symbolick link to your images folder from the Mobile folder. 您可以从Mobile文件夹中为images文件夹创建符号链接。

If you have shell access, inside the Mobile folder do: 如果您有shell访问权限,请在Mobile文件夹中执行:

ln -s /path/to/document/root/ProImages ./ProImages

That way you can call for Mobile/ProImages and the contents being displayed are from ProImages from the parent folder. 这样您就可以调用Mobile/ProImages ,显示的内容来自父文件夹中的ProImages

Normally I'm all for redirecting using the server but for mobile using PHP. 通常我都是使用服务器进行重定向,但是使用PHP进行移动。 I recommend using mobile_detect class. 我建议使用mobile_detect类。 I works extremely well and it matches on just about everything. 我的工作非常好 ,几乎所有东西都匹配。 You can even detect based on specifics such as if on a tablet or an ipad or whatever you want. 您甚至可以根据具体情况进行检测,例如在平板电脑或ipad上或您想要的任何内容。 It's very easy to use rather than doing user agent with .htaccess. 它非常容易使用,而不是使用.htaccess执行用户代理。 So you can do an if statement like below and then do a redirect with php. 所以你可以像下面那样做一个if语句,然后用php重定向。

Here is code samples for their page. 这是他们页面的代码示例。 http://mobiledetect.net/ http://mobiledetect.net/

// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;

// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
  header('Location: http://m.example.com/'.$_SERVER["REQUEST_URI"]);
}

// Any tablet device.
if( $detect->isTablet() ){

}

// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){

}

// Check for a specific platform with the help of the magic methods:
if( $detect->isiOS() ){

}

if( $detect->isAndroidOS() ){

}

// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->is('Chrome')
$detect->is('iOS')
$detect->is('UC Browser')
// [...]

// Batch mode using setUserAgent():
$userAgents = array(
'Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103',
// [...]
);
foreach($userAgents as $userAgent){

  $detect->setUserAgent($userAgent);
  $isMobile = $detect->isMobile();
  $isTablet = $detect->isTablet();
  // Use the force however you want.

}

// Get the version() of components.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->version('iPad'); // 4.3 (float)
$detect->version('iPhone') // 3.1 (float)
$detect->version('Android'); // 2.1 (float)
$detect->version('Opera Mini'); // 5.0 (float)
// [...]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM