htaccess,使用ajax重定向到子文件夹,并调用父目录的资源[PHP]

时间:2018-07-25 03:11:17

标签: php ajax .htaccess

每个人,我都有这样的体系结构:

DESKTOP_VERSION (root folder)
|--files
|-api_files
|----MOBILE_VERSION
     |--files

desktop_version和mobile_version使用相同的api_files。问题是:当来自移动设备时,用户将被重定向到移动目录: 我在.htaccess

中使用了此命令
RewriteEngine on
RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Android 3.0|Pad|Xoom|Flyer|tablet" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "nokia|iphone|android|motorola|^mot-|^lct|^lg-|\(webos/" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "softbank|foma|docomo|kddi|up\.browser|up\.link" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "htc|dopod|blazer|netfront|helio|hosin|huawei|xda" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "novarra|coolpad|webos|techfaith|palmsource|^vodafone" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mobile\ssafari|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|smartphone|midp|wap|phone|iemobile|^spice" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "jig browser|hiptop|^ucweb|^benq|haier|vertuascent" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "opera mobi|opera mini|320x320|240x320|176x220" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "minimo|windows ce|avantgo|ppc; mda|ipod|pocketpc" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palmos|mobileexplorer|maemo browser|configuration/cldc" [NC]
RewriteCond %{HTTP_USER_AGENT} !Googlebot-Mobile [NC]
RewriteRule ^$ mobile_version [L]

例如,它仅重定向根文件夹:如果用户使用手机来自myapp.com,则他正确地重定向到myapp.com/mobile_version

但是,如果他来自myapp.com/about,他将不会重定向至mobile_version 我知道是因为 RewriteRule ^ $ eagence_mobile [L] ,所以我使用了以下内容:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !/mobile_version/**

RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Android 3.0|Pad|Xoom|Flyer|tablet" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "nokia|iphone|android|motorola|^mot-|^lct|^lg-|\(webos/" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "softbank|foma|docomo|kddi|up\.browser|up\.link" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "htc|dopod|blazer|netfront|helio|hosin|huawei|xda" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "novarra|coolpad|webos|techfaith|palmsource|^vodafone" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mobile\ssafari|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|smartphone|midp|wap|phone|iemobile|^spice" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "jig browser|hiptop|^ucweb|^benq|haier|vertuascent" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "opera mobi|opera mini|320x320|240x320|176x220" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "minimo|windows ce|avantgo|ppc; mda|ipod|pocketpc" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palmos|mobileexplorer|maemo browser|configuration/cldc" [NC]
RewriteCond %{HTTP_USER_AGENT} !Googlebot-Mobile [NC]
RewriteRule ^(.*)$ mobile_version/$1 [L]

用户已正确重定向,但现在对api_files之类的父目录的ajax调用失败,并且对父目录的某些文件的调用(桌面版本失败)  请注意,在第一种情况下(第一个.htaccess),除用户未正确重定向外,其他所有功能均正常运行(对父目录,资源等的API调用)。

期待什么 如果移动用户访问myapp.com/about,他将被重定向到myapp.com/mobile_version/about,并且我所有的ajax调用到父目录的资源均正常工作。

我不知道该怎么办或做错了什么。预先感谢

0 个答案:

没有答案