[英]Access folder of parent website from mobile website after htaccess redirect
我通過移動設備訪問時將我的網站重定向到移動網站。
這是htaccess代碼:
RewriteCond %{QUERY_STRING} !^desktop
RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|iphone [NC]
RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]
FTP的文件夾結構如下:
Images
ProImages
Mobile // All mobile site data into this
當我嘗試從我的移動網站訪問http://www.example.com/ProImages/abc.jpg
,它沒有顯示,因為一旦它嘗試調用www
,它就會重定向到m
。
我嘗試使用../ProImages
但這又沒有解決問題。
有人可以幫忙嗎?
您可以允許訪問移動版本的圖像文件夾
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]
您可以從Mobile文件夾中為images文件夾創建符號鏈接。
如果您有shell訪問權限,請在Mobile文件夾中執行:
ln -s /path/to/document/root/ProImages ./ProImages
這樣您就可以調用Mobile/ProImages
,顯示的內容來自父文件夾中的ProImages
。
通常我都是使用服務器進行重定向,但是使用PHP進行移動。 我建議使用mobile_detect類。 我的工作非常好 ,幾乎所有東西都匹配。 您甚至可以根據具體情況進行檢測,例如在平板電腦或ipad上或您想要的任何內容。 它非常容易使用,而不是使用.htaccess執行用戶代理。 所以你可以像下面那樣做一個if語句,然后用php重定向。
這是他們頁面的代碼示例。 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.